Unverified Commit 73253a06 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Bytecode + Block decomposition: fix crash with purely forward variables

After simulating a block containing purely forward variables (thus of type
“evaluate backward”), the it_ variable of the evaluator would be left in an
inconsistent state (typically 0, which means that taking the value of a lagged
variable would lead to an invalid read).

By the way, fix a symmetric problem for backward blocks (which could
potentially create a invalid read for purely backward models).

Ref. #1727
parent 8803bc14
......@@ -1513,6 +1513,7 @@ Evaluate::evaluate_over_periods(const bool forward)
it_code = begining;
compute_block_time(0, false, false);
}
it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
}
else
{
......@@ -1521,6 +1522,7 @@ Evaluate::evaluate_over_periods(const bool forward)
it_code = begining;
compute_block_time(0, false, false);
}
it_ = y_kmin; // Do not leave it_ in inconsistent state (see #1727)
}
}
}
......@@ -1596,11 +1598,17 @@ Evaluate::solve_simple_over_periods(const bool forward)
else
{
if (forward)
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
solve_simple_one_periods();
{
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
solve_simple_one_periods();
it_= periods+y_kmin-1; // Do not leave it_ in inconsistent state
}
else
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
solve_simple_one_periods();
{
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
solve_simple_one_periods();
it_ = y_kmin; // Do not leave it_ in inconsistent state (see #1727)
}
}
mxFree(g1);
mxFree(r);
......@@ -1665,6 +1673,7 @@ Evaluate::compute_complete_2b(const bool no_derivatives, double *_res1, double *
else
return;
}
it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
return;
}
......@@ -1757,6 +1766,7 @@ Evaluate::compute_complete(double lambda, double *crit)
else
return false;
}
it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
}
mexPrintf(" lambda=%e, res2=%e\n", lambda, res2_);
*crit = res2_/2;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment