aboutsummaryrefslogtreecommitdiff
path: root/src/lj_cparse.c
diff options
context:
space:
mode:
authorMike Pall <mike>2022-12-22 00:03:06 +0100
committerMike Pall <mike>2022-12-22 00:03:06 +0100
commit8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b (patch)
treedae089564f58db2963bae8e3530c1faae104cc61 /src/lj_cparse.c
parentb2791179ef96d652d00d78d2a8780af690537f6a (diff)
downloadluajit-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_cparse.c')
-rw-r--r--src/lj_cparse.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lj_cparse.c b/src/lj_cparse.c
index df85d23b..8c681c56 100644
--- a/src/lj_cparse.c
+++ b/src/lj_cparse.c
@@ -477,7 +477,7 @@ static void cp_expr_prefix(CPState *cp, CPValue *k)
477 } else if (cp_opt(cp, '+')) { 477 } else if (cp_opt(cp, '+')) {
478 cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */ 478 cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */
479 } else if (cp_opt(cp, '-')) { 479 } else if (cp_opt(cp, '-')) {
480 cp_expr_unary(cp, k); k->i32 = -k->i32; 480 cp_expr_unary(cp, k); k->i32 = (int32_t)(~(uint32_t)k->i32+1);
481 } else if (cp_opt(cp, '~')) { 481 } else if (cp_opt(cp, '~')) {
482 cp_expr_unary(cp, k); k->i32 = ~k->i32; 482 cp_expr_unary(cp, k); k->i32 = ~k->i32;
483 } else if (cp_opt(cp, '!')) { 483 } else if (cp_opt(cp, '!')) {