From 072549f378b992da1ff2d4964e8ec2ee44224ece Mon Sep 17 00:00:00 2001 From: Miraculous Ladybugreport <3642643+PeyTy@users.noreply.github.com> Date: Thu, 23 May 2024 20:28:02 +0300 Subject: [PATCH] [Native] Avoid overwrite with zero --- source/targets/genC.hexa | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/source/targets/genC.hexa b/source/targets/genC.hexa index 3aca2ad..181bc3a 100644 --- a/source/targets/genC.hexa +++ b/source/targets/genC.hexa @@ -738,16 +738,24 @@ class GenCxx { } if defaults { - //types.push('void* ' + name + '_;\n') - globalVariables.push(stringifyType(type)) - globalVariables.push(' ' + name + '_;\n') - if expr != null { - out.push('\t' + name + '_ = ' + printExpression(expr) + ';\n') - } + //types.push('void* ' + name + '_;\n') + globalVariables.push(stringifyType(type)) + globalVariables.push(' ' + name + '_;\n') + if expr != null { + let value String = printExpression(expr) + + // Printing zero global integers causes bug in Hexa runtime code + // due to assignment of heap offset of zero after strings allocation + // Also in C global values are guaranteed to be initialized to 0 + // TODO check for `project.typer.typeInt` and other integer types + if value != '(int32_t)0' { + out.push('\t' + name + '_ = ' + value + ';\n') + } + } } //out.push('\n\tvar ' + name) //if (expr != null) out.push(' = ' + printExpression(expr)) - // TODO meybe not useful + // TODO maybe not useful //else out.push(' = null') case Const(name, expr, type): globalVariables.push(stringifyType(type))