From dfdc4b5f83deb595cfb19d2ea5a48b764d3acd6a Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Wed, 17 Sep 2025 12:55:54 +0100 Subject: [PATCH 1/2] [cppia] Fix int overflow in arithmetic assignments Currently, the cppia interp runtime uses float operations for arithmetic assignments such as *=. This results in inconsistent int overflow behaviour. --- src/hx/cppia/Cppia.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hx/cppia/Cppia.h b/src/hx/cppia/Cppia.h index b8361537c..0137f2937 100644 --- a/src/hx/cppia/Cppia.h +++ b/src/hx/cppia/Cppia.h @@ -1083,6 +1083,14 @@ struct NAME \ ioVal = left OP f; \ return ioVal; \ } \ + inline static int &run(int &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) \ + { \ + int left = ioVal; \ + int i = value->runInt(ctx); \ + BCR_CHECK_RET(ioVal); \ + ioVal = left OP i; \ + return ioVal; \ + } \ static bool run(bool &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) { value->runVoid(ctx); return ioVal; } \ static String run(String &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) { value->runVoid(ctx); return ioVal; } \ static hx::Object *run(hx::Object * &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) \ From 31cde08326221f4ae8692e49d72ab9a7c014845a Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Wed, 17 Sep 2025 12:56:25 +0100 Subject: [PATCH 2/2] [tests] Add regression test for int *= overflow --- test/cppia/Client.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/cppia/Client.hx b/test/cppia/Client.hx index 67842a75a..391945db2 100644 --- a/test/cppia/Client.hx +++ b/test/cppia/Client.hx @@ -189,6 +189,14 @@ class Client default: } + // regression test for #1257 + var x = 1290555; + x *= 1290555; + if (x != -915102823) { + Common.status = 'Failed regression test for #1257. x: $x'; + return; + } + final extending = new ClientExtendedExtendedRoot(); extending.addValue();