Skip to content

Commit

Permalink
avoid underflow of unsigned size_t and access to NULL if there are no…
Browse files Browse the repository at this point in the history
… real variables

This follows up r25740 (see Modelica.Utilities.Examples.readRealParameterModel).


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25747 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
rfranke committed Apr 26, 2015
1 parent 6ddc316 commit 831361e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions SimulationRuntime/cpp/Core/System/SimVars.cpp
Expand Up @@ -87,8 +87,8 @@ bool& SimVars::initBoolVar(size_t i)
*/
double* SimVars::getStateVector()
{
if (_z_i + _dim_z - 1 < _dim_real)
return &_real_vars.get()->get()[_z_i];
if (_z_i + _dim_z <= _dim_real)
return _dim_real > 0? &_real_vars.get()->get()[_z_i]: NULL;
else
throw std::runtime_error("Wrong state vars start index");
}
Expand All @@ -99,10 +99,10 @@ double* SimVars::getStateVector()
*/
double* SimVars::getDerStateVector()
{
if (_z_i + _dim_z - 1 < _dim_real)
return &_real_vars.get()->get()[_z_i + _dim_z];
if (_z_i + 2*_dim_z <= _dim_real)
return _dim_real > 0? &_real_vars.get()->get()[_z_i + _dim_z]: NULL;
else
throw std::runtime_error("Wrong state vars start index");
throw std::runtime_error("Wrong der state vars start index");
}
/**
* \brief returns real vars vector of size dim_real
Expand Down

0 comments on commit 831361e

Please sign in to comment.