Skip to content
Snippets Groups Projects
Commit b362e591 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fixed bug. Uninitialized memory reads because the code was working with a...

Fixed bug. Uninitialized memory reads because the code was working with a std::map, which was volatile.

(cherry picked from commit 7ca36832)
parent 139f5ae7
Branches
No related tags found
No related merge requests found
// Copyright (C) 2006-2011, Ondra Kamenik // Copyright (C) 2006-2011, Ondra Kamenik
#include "forw_subst_builder.h" #include "forw_subst_builder.h"
using namespace ogdyn; using namespace ogdyn;
...@@ -47,18 +48,20 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j) ...@@ -47,18 +48,20 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j)
// first make lagsubst be substitution setting f(x(+4)) to f(x(+1)) // first make lagsubst be substitution setting f(x(+4)) to f(x(+1))
// this is lag = -3 (1-mlead) // this is lag = -3 (1-mlead)
map<int,int> lagsubst; map<int,int> lagsubst;
model.variable_shift_map(model.eqs.nulary_of_term(t), 1-mlead, lagsubst); unordered_set<int> nult = model.eqs.nulary_of_term(t);// make copy of nult!
model.variable_shift_map(nult, 1-mlead, lagsubst);
int lagt = model.eqs.add_substitution(t, lagsubst); int lagt = model.eqs.add_substitution(t, lagsubst);
// now maxlead of lagt is +1
// add AUXLD_*_*_1 = f(x(+1)) to the model // now maxlead of lagt is +1
char name[100]; // add AUXLD_*_*_1 = f(x(+1)) to the model
sprintf(name, "AUXLD_%d_%d_%d", i, j, 1); char name[100];
model.atoms.register_uniq_endo(name); sprintf(name, "AUXLD_%d_%d_%d", i, j, 1);
info.num_aux_variables++; model.atoms.register_uniq_endo(name);
const char* ss = model.atoms.get_name_storage().query(name); info.num_aux_variables++;
int auxt = model.eqs.add_nulary(name); const char* ss = model.atoms.get_name_storage().query(name);
model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt)); int auxt = model.eqs.add_nulary(name);
aux_map.insert(Tsubstmap::value_type(ss, lagt)); model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt));
aux_map.insert(Tsubstmap::value_type(ss, lagt));
// now add variables and equations // now add variables and equations
// AUXLD_*_*_2 = AUXLD_*_*_1(+1) through // AUXLD_*_*_2 = AUXLD_*_*_1(+1) through
// AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1) // AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1)
...@@ -82,7 +85,9 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j) ...@@ -82,7 +85,9 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j)
aux_map.insert(Tsubstmap::value_type(ss, lagt)); aux_map.insert(Tsubstmap::value_type(ss, lagt));
} }
// now we have to substitute AUXLEAD_*_*{mlead-1}(+1) for t // now we have to substitute AUXLD_*_*{mlead-1}(+1) for t
sprintf(name, "AUXLD_%d_%d_%d", i, j, mlead-1);
ss = model.atoms.get_name_storage().query(name);
model.substitute_atom_for_term(ss, +1, t); model.substitute_atom_for_term(ss, +1, t);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment