Check that there is space in local variable array

Otherwise it can overflow due to for loop's hidden
variables.

Fix #561
This commit is contained in:
Aleksi Salmela
2018-06-13 00:59:55 +03:00
parent 40c927f440
commit e7b1bade1a
2 changed files with 188 additions and 0 deletions
+10
View File
@@ -2906,6 +2906,16 @@ static void forStatement(Compiler* compiler)
// The space in the variable name ensures it won't collide with a user-defined
// variable.
expression(compiler);
// Verify that there is space to hidden local variables.
// Note that we expect only two addLocal calls next to each other in the
// following code.
if (compiler->numLocals + 2 > MAX_LOCALS)
{
error(compiler, "Cannot declare more than %d variables in one scope. (Not enough space for for-loops internal variables)",
MAX_LOCALS);
return;
}
int seqSlot = addLocal(compiler, "seq ", 4);
// Create another hidden local for the iterator object.