From ca76cc67b7e3c50e8ebb7e1d1e4f250bb82038ea Mon Sep 17 00:00:00 2001 From: hellkite500 Date: Wed, 26 Apr 2023 07:15:45 -0600 Subject: [PATCH] Prevent basic_string exception trying to take substr of an empty string --- include/realizations/catchment/AbstractCLibBmiAdapter.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/realizations/catchment/AbstractCLibBmiAdapter.hpp b/include/realizations/catchment/AbstractCLibBmiAdapter.hpp index ccf0dd92d8..337c1660df 100644 --- a/include/realizations/catchment/AbstractCLibBmiAdapter.hpp +++ b/include/realizations/catchment/AbstractCLibBmiAdapter.hpp @@ -91,7 +91,12 @@ namespace models { if (!utils::FileChecker::file_is_readable(bmi_lib_file)) { //Try alternative extension... size_t idx = bmi_lib_file.rfind("."); - std::string alt_bmi_lib_file; + std::string alt_bmi_lib_file; + if(bmi_lib_file.length() == 0){ + this->init_exception_msg = + "Can't init " + this->model_name + "; library file path is empty"; + throw std::runtime_error(this->init_exception_msg); + } if(bmi_lib_file.substr(idx) == ".so"){ alt_bmi_lib_file = bmi_lib_file.substr(0,idx) + ".dylib"; } else if(bmi_lib_file.substr(idx) == ".dylib"){