Skip to content

Commit

Permalink
fix induction variable update bug identified by LeartS
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmeza committed Oct 24, 2014
1 parent a315f2b commit 9420332
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3471,12 +3471,19 @@ ReturnObject *interpretLoopStmtNode(StmtNode *node,
* variable.
*/
if (stmt->update->type == ET_OP) {
ValueObject *updated = NULL;
var = getScopeValue(scope, outer, stmt->var);
OpExprNode *op = (OpExprNode *)stmt->update->expr;
if (op->type == OP_ADD)
var->data.i++;
updated = createIntegerValueObject(var->data.i + 1);
else if (op->type == OP_SUB)
var->data.i--;
updated = createIntegerValueObject(var->data.i - 1);

if (!updateScopeValue(scope, outer, stmt->var, updated)) {
deleteValueObject(updated);
deleteScopeObject(outer);
return NULL;
}
}
else {
ValueObject *update = interpretExprNode(stmt->update, outer);
Expand Down

0 comments on commit 9420332

Please sign in to comment.