Skip to content

Commit 767fe94

Browse files
authored
[cppia] Fix int overflow in arithmetic assignments (#1258)
* [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. * [tests] Add regression test for int *= overflow
1 parent 0c37f06 commit 767fe94

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/hx/cppia/Cppia.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,14 @@ struct NAME \
10831083
ioVal = left OP f; \
10841084
return ioVal; \
10851085
} \
1086+
inline static int &run(int &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) \
1087+
{ \
1088+
int left = ioVal; \
1089+
int i = value->runInt(ctx); \
1090+
BCR_CHECK_RET(ioVal); \
1091+
ioVal = left OP i; \
1092+
return ioVal; \
1093+
} \
10861094
static bool run(bool &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) { value->runVoid(ctx); return ioVal; } \
10871095
static String run(String &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) { value->runVoid(ctx); return ioVal; } \
10881096
static hx::Object *run(hx::Object * &ioVal, hx::CppiaCtx *ctx, hx::CppiaExpr *value) \

test/cppia/Client.hx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ class Client
197197
return;
198198
}
199199

200+
// regression test for #1257
201+
var x = 1290555;
202+
x *= 1290555;
203+
if (x != -915102823) {
204+
Common.status = 'Failed regression test for #1257. x: $x';
205+
return;
206+
}
207+
200208
final extending = new ClientExtendedExtendedRoot();
201209

202210
extending.addValue();

0 commit comments

Comments
 (0)