Merge pull request #48793 from vnen/gdscript-fix-temp-type-adjust

GDScript: Fix crash caused by uninitialized temp stack slots
This commit is contained in:
Rémi Verschelde 2021-05-17 17:34:19 +02:00 committed by GitHub
commit 2fcfc83da9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 7 deletions

View file

@ -129,12 +129,6 @@ uint32_t GDScriptByteCodeGenerator::add_temporary(const GDScriptDataType &p_type
int idx = temporaries.size();
pool.push_back(idx);
temporaries.push_back(new_temp);
// First time using this, so adjust to the proper type.
if (temp_type != Variant::NIL) {
Address addr(Address::TEMPORARY, idx, p_type);
write_type_adjust(addr, temp_type);
}
}
int slot = pool.front()->get();
pool.pop_front();
@ -189,8 +183,12 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
append(GDScriptFunction::OPCODE_END, 0);
for (int i = 0; i < temporaries.size(); i++) {
int stack_index = i + max_locals + RESERVED_STACK;
for (int j = 0; j < temporaries[i].bytecode_indices.size(); j++) {
opcodes.write[temporaries[i].bytecode_indices[j]] = (i + max_locals + RESERVED_STACK) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
opcodes.write[temporaries[i].bytecode_indices[j]] = stack_index | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
}
if (temporaries[i].type != Variant::NIL) {
function->temporary_slots[stack_index] = temporaries[i].type;
}
}