Skip to content

Commit

Permalink
Fix conditional jump on uninitialised value (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored Nov 22, 2024
1 parent 06e807b commit d807d7a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/OMSimulator/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ typedef struct {
char* conA; ///< Name of connector A
char* conB; ///< Name of connector B
ssd_connection_geometry_t* geometry; ///< Geometry information of the connection
bool suppressUnitConversion; ///< boolean to specify automatic unit coversion between connections
bool suppressUnitConversion; ///< Boolean to specify if automatic unit conversion between connections should be suppressed
} oms_connection_t;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/OMSimulatorLib/DirectedGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ void oms::DirectedGraph::calculateSortedConnections()
scc.component_names.insert(conB.getOwner());
// check for factor in connector units
if (nodes[edges.connections[components[i][j]].first].connectorUnits.empty() || nodes[edges.connections[components[i][j]].second].connectorUnits.empty())
{
scc.factor = 1.0;
scc.suppressUnitConversion = true;
}
else
{
double factorA = 1.0;
Expand Down
6 changes: 3 additions & 3 deletions src/OMSimulatorLib/SystemSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ oms_status_enu_t oms::SystemSC::updateInputs(DirectedGraph& graph)
{
double value = 0.0;
if (oms_status_ok != getReal(graph.getNodes()[output].getName(), value)) return oms_status_error;
/* check for unit conversion and suppressUnitConversion and set the value multiplied by factor,
* by default, factor = 1.0, (e.g) mm to m will be (factor*value) => (10^-3 * value)
*/

// Check for unit conversion and suppressUnitConversion. Set the value multiplied by factor.
// By default, factor = 1.0. For example, mm to m will be (factor * value) => (1e-3 * value).
if (sortedConnections[i].suppressUnitConversion)
value = value;
else
Expand Down
12 changes: 6 additions & 6 deletions src/OMSimulatorLib/SystemWC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,20 +1034,20 @@ oms_status_enu_t oms::SystemWC::updateInputs(oms::DirectedGraph& graph)
const std::vector<scc_t>& sortedConnections = graph.getSortedConnections();
updateAlgebraicLoops(sortedConnections, graph);

for(int i=0; i < sortedConnections.size(); i++)
for(size_t i=0; i < sortedConnections.size(); i++)
{
if (!sortedConnections[i].thisIsALoop)
{
int output = sortedConnections[i].connections[0].first;
int input = sortedConnections[i].connections[0].second;
size_t output = sortedConnections[i].connections[0].first;
size_t input = sortedConnections[i].connections[0].second;

if (graph.getNodes()[input].getType() == oms_signal_type_real)
{
double value = 0.0;
if (oms_status_ok != getReal(graph.getNodes()[output].getName(), value)) return oms_status_error;
/* check for unit conversion and suppressUnitConversion and set the value multiplied by factor,
* by default, factor = 1.0, (e.g) mm to m will be (factor*value) => (10^-3 * value)
*/

// Check for unit conversion and suppressUnitConversion. Set the value multiplied by factor.
// By default, factor = 1.0. For example, mm to m will be (factor * value) => (10^-3 * value).
if (sortedConnections[i].suppressUnitConversion)
value = value;
else
Expand Down
1 change: 1 addition & 0 deletions testsuite/simulation/renameValues2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-- ucrt64: yes
-- win: yes
-- mac: no
-- asan: yes

oms_setCommandLineOption("--suppressPath=true")
oms_setTempDirectory("./renameValues2_lua/")
Expand Down

0 comments on commit d807d7a

Please sign in to comment.