From bcc897235641576e9b1c6527a160aa314e703f8e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 1 Mar 2018 15:00:18 +0100 Subject: [PATCH] - fixed: A preincrement of a local variable generated wrong code if passed as a function parameter. Due to the special nature of this expression the code generator got stuck in 'address' mode and passed the address of the variable instead of its value. --- src/scripting/backend/codegen.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 24e541a36..273d4e498 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -2304,6 +2304,7 @@ ExpEmit FxPreIncrDecr::Emit(VMFunctionBuilder *build) } pointer.Free(build); + value.Target = false; // This is for 'unrequesting' the address of a register variable. If not done here, passing a preincrement expression to a function will generate bad code. return value; } @@ -7406,7 +7407,16 @@ ExpEmit FxArrayElement::Emit(VMFunctionBuilder *build) if (arrayispointer) { - arraytype = static_cast(Array->ValueType->toPointer()->PointedType); + auto ptr = Array->ValueType->toPointer(); + if (ptr != nullptr) + { + arraytype = static_cast(ptr->PointedType); + } + else + { + ScriptPosition.Message(MSG_ERROR, "Internal error when generating code for array access"); + return ExpEmit(); + } } else {