mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added an out-of-bounds check
This commit is contained in:
@@ -1606,7 +1606,23 @@ static bool execIndexAssign(Interpreter* interpreter) {
|
||||
|
||||
//call the function
|
||||
NativeFn fn = (NativeFn)AS_FUNCTION(func).bytecode;
|
||||
fn(interpreter, &arguments);
|
||||
if (fn(interpreter, &arguments) == -1) {
|
||||
//clean up
|
||||
freeLiteral(assign);
|
||||
freeLiteral(third);
|
||||
freeLiteral(second);
|
||||
freeLiteral(first);
|
||||
freeLiteral(compound);
|
||||
if (freeIdn) {
|
||||
freeLiteral(idn);
|
||||
}
|
||||
freeLiteral(func);
|
||||
freeLiteral(key);
|
||||
freeLiteral(op);
|
||||
freeLiteralArray(&arguments);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//save the result (assume top of the interpreter stack is the new compound value)
|
||||
Literal result = popLiteralArray(&interpreter->stack);
|
||||
|
||||
@@ -495,7 +495,19 @@ int _index(Interpreter* interpreter, LiteralArray* arguments) {
|
||||
|
||||
if (IS_NULL(second)) {
|
||||
//set the "first" within the array, then skip out
|
||||
setLiteralArray(AS_ARRAY(compound), first, assign);
|
||||
if (!setLiteralArray(AS_ARRAY(compound), first, assign)) {
|
||||
interpreter->errorOutput("Index assignment out of bounds\n");
|
||||
|
||||
freeLiteral(op);
|
||||
freeLiteral(assign);
|
||||
freeLiteral(third);
|
||||
freeLiteral(second);
|
||||
freeLiteral(first);
|
||||
freeLiteral(compound);
|
||||
freeLiteral(value);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
pushLiteralArray(&interpreter->stack, compound);
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ bool setLiteralArray(LiteralArray* array, Literal index, Literal value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: implicit push when referencing one-past-the-end?
|
||||
|
||||
freeLiteral(array->literals[idx]);
|
||||
array->literals[idx] = copyLiteral(value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user