Fix potential references to bad stacks due to ordering of array indexing

This commit is contained in:
K. Lange 2024-02-15 17:48:00 +09:00
parent e9702ad37e
commit c179b7f4b4

View File

@ -1790,10 +1790,12 @@ static int valueGetProperty(KrkString * name) {
krk_currentThread.stackTop[-2] = krk_currentThread.stackTop[-1]; krk_currentThread.stackTop[-2] = krk_currentThread.stackTop[-1];
krk_currentThread.stackTop--; krk_currentThread.stackTop--;
return 1; return 1;
case 1: case 1: {
krk_currentThread.stackTop[-2] = OBJECT_VAL(krk_newBoundMethod(krk_currentThread.stackTop[-2], AS_OBJECT(krk_currentThread.stackTop[-1]))); KrkValue o = OBJECT_VAL(krk_newBoundMethod(krk_currentThread.stackTop[-2], AS_OBJECT(krk_currentThread.stackTop[-1])));
krk_currentThread.stackTop[-2] = o;
krk_currentThread.stackTop--; krk_currentThread.stackTop--;
return 1; return 1;
}
default: default:
return 0; return 0;
} }
@ -1911,16 +1913,19 @@ static int valueSetProperty(KrkString * name) {
return 1; return 1;
} }
if (IS_INSTANCE(owner)) { if (IS_INSTANCE(owner)) {
krk_currentThread.stackTop[-1] = setAttr_wrapper(owner,type,&AS_INSTANCE(owner)->fields, name, value); KrkValue o = setAttr_wrapper(owner,type,&AS_INSTANCE(owner)->fields, name, value);
krk_currentThread.stackTop[-1] = o;
} else if (IS_CLASS(owner)) { } else if (IS_CLASS(owner)) {
krk_currentThread.stackTop[-1] = setAttr_wrapper(owner,type,&AS_CLASS(owner)->methods, name, value); KrkValue o = setAttr_wrapper(owner,type,&AS_CLASS(owner)->methods, name, value);
krk_currentThread.stackTop[-1] = o;
if (name->length > 1 && name->chars[0] == '_' && name->chars[1] == '_') { if (name->length > 1 && name->chars[0] == '_' && name->chars[1] == '_') {
krk_finalizeClass(AS_CLASS(owner)); krk_finalizeClass(AS_CLASS(owner));
} else { } else {
clearCache(AS_CLASS(owner)); clearCache(AS_CLASS(owner));
} }
} else if (IS_CLOSURE(owner)) { } else if (IS_CLOSURE(owner)) {
krk_currentThread.stackTop[-1] = setAttr_wrapper(owner,type,&AS_CLOSURE(owner)->fields, name, value); KrkValue o = setAttr_wrapper(owner,type,&AS_CLOSURE(owner)->fields, name, value);
krk_currentThread.stackTop[-1] = o;
} else { } else {
if (_setDescriptor(owner,type,name,value)) { if (_setDescriptor(owner,type,name,value)) {
krk_swap(1); krk_swap(1);