diff options
author | Mike Pall <mike> | 2022-12-22 00:03:06 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2022-12-22 00:03:06 +0100 |
commit | 8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b (patch) | |
tree | dae089564f58db2963bae8e3530c1faae104cc61 /src/lj_carith.c | |
parent | b2791179ef96d652d00d78d2a8780af690537f6a (diff) | |
download | luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.tar.gz luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.tar.bz2 luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.zip |
Avoid negation of signed integers in C that may hold INT*_MIN.
Reported by minoki.
Recent C compilers 'take advantage' of the undefined behavior.
This completely changes the meaning of expressions like (k == -k).
Diffstat (limited to 'src/lj_carith.c')
-rw-r--r-- | src/lj_carith.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lj_carith.c b/src/lj_carith.c index 462dbae4..231d7a8a 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c | |||
@@ -205,7 +205,7 @@ static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm) | |||
205 | else | 205 | else |
206 | *up = lj_carith_powu64(u0, u1); | 206 | *up = lj_carith_powu64(u0, u1); |
207 | break; | 207 | break; |
208 | case MM_unm: *up = (uint64_t)-(int64_t)u0; break; | 208 | case MM_unm: *up = ~u0+1u; break; |
209 | default: lua_assert(0); break; | 209 | default: lua_assert(0); break; |
210 | } | 210 | } |
211 | lj_gc_check(L); | 211 | lj_gc_check(L); |