diff --git a/CMakeLists.txt b/CMakeLists.txt index ed4f8b5..ec6d307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,25 +5,23 @@ project(chemmisol VERSION 0.1) # GoogleTest requires at least C++14 set(CMAKE_CXX_STANDARD 14) +set(CHEMMISOL_MEMORY_SANITIZE NO CACHE BOOL "Enables -fsanitize=address.") + set(CMAKE_CXX_FLAGS_DEBUG "\ ${CMAKE_CXX_FLAGS_DEBUG} -std=c++14 \ --Wall -Wextra -Wpedantic -Werror -Wno-error=pedantic \ +-Wall -Wextra -Wpedantic -Wno-error=pedantic \ -Woverloaded-virtual -Wnon-virtual-dtor \ --fsanitize=address \ -Wno-range-loop-construct \ ") +if(CHEMMISOL_MEMORY_SANITIZE) + message(STATUS "Enabling -fsanitize=address") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address") +endif() set(CHEMMISOL_LOCAL_EASYLOGGING "" CACHE PATH "Path to easylogging++ sources. If not specified, sources will be downloaded at configure time." ) -if($$) - message(STATUS "DEBUG") -endif() -if($$) - message(STATUS "RELEASE") -endif() - if(CHEMMISOL_LOCAL_EASYLOGGING) set(EASYLOGGING_SRC_PATH ${CHEMMISOL_LOCAL_EASYLOGGING}) else() diff --git a/src/chemmisol/chemical.cpp b/src/chemmisol/chemical.cpp index a3573ce..f34d5ca 100644 --- a/src/chemmisol/chemical.cpp +++ b/src/chemmisol/chemical.cpp @@ -143,6 +143,10 @@ namespace chemmisol { break; case SOLVENT: fixed_component = new Solvent(name, index); + break; + default: + // Should not append + fixed_component = nullptr; } components[index].reset(fixed_component); existing_component->second = fixed_component; @@ -347,7 +351,7 @@ namespace chemmisol { // The limiting reactive is used to define the maximum possible // extent of the reaction so that all reagent concentrations stay // positive. - const Component* limiting_reactive; + const Component* limiting_reactive = nullptr; double limiting_reactive_coefficient = 0; double smallest_limiting_factor = std::numeric_limits::infinity(); @@ -375,7 +379,7 @@ namespace chemmisol { GuessF f = GuessF(*this, *reaction, guessed_concentrations); double max_N; - if(smallest_limiting_factor < std::numeric_limits::infinity()) { + if(limiting_reactive != nullptr) { CHEM_LOG(DEBUG) << " Limiting reactive: " << limiting_reactive_coefficient << " " << limiting_reactive->getName() << " " << limiting_reactive_coefficient * smallest_limiting_factor << " mol/l";