Skip to content

Commit c0289be

Browse files
committed
BIFs: neg_boxed_helper use minimum boxed size (on 32-bit systems)
On 32-bit systems, use `make_maybe_boxed_int64` in `neg_boxed_helper` since `-(INT32_MAX + 1)` is `INT32_MIN` that fits into a 32-bit boxed integer. Before of this change `make_boxed_int64` was used, making a 64-bit boxed integer for an int32 value. New `term_compare` implementation will check size and sign metadata before performing any actual comparison, so all value must be in their "minimal canonical form". Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent 7b0316a commit c0289be

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/libAtomVM/bif.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,9 @@ static term neg_boxed_helper(Context *ctx, uint32_t fail_label, uint32_t live, t
10511051
RAISE_ERROR_BIF(fail_label, OVERFLOW_ATOM);
10521052

10531053
} else {
1054-
return make_boxed_int64(ctx, fail_label, live, -val);
1054+
// maybe boxed int64 since we need to handle -(AVM_INT_MAX + 1) that is
1055+
// AVM_INT_MIN that fits into a 32 bit boxed value
1056+
return make_maybe_boxed_int64(ctx, fail_label, live, -val);
10551057
}
10561058
}
10571059
#endif

0 commit comments

Comments
 (0)