Skip to content

Commit

Permalink
Indexing into a vector past its end is UB.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Apr 24, 2022
1 parent 9d9ed3b commit e98428c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ ExecutionResult execute(
case Instr::end:
{
// End execution if it's a final end instruction.
if (pc == &code.instructions[code.instructions.size()])
if (pc == code.instructions.data() + code.instructions.size())
goto end;
break;
}
Expand Down Expand Up @@ -1563,7 +1563,8 @@ ExecutionResult execute(
}

end:
assert(pc == &code.instructions[code.instructions.size()]); // End of code must be reached.
assert(pc == code.instructions.data() + code.instructions.size()); // End of code must be
// reached.
assert(stack.size() == instance.module->get_function_type(func_idx).outputs.size());

return stack.size() != 0 ? ExecutionResult{stack.top()} : Void;
Expand Down

0 comments on commit e98428c

Please sign in to comment.