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).
This commit is contained in:
@@ -477,7 +477,7 @@ static void cp_expr_prefix(CPState *cp, CPValue *k)
|
||||
} else if (cp_opt(cp, '+')) {
|
||||
cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */
|
||||
} else if (cp_opt(cp, '-')) {
|
||||
cp_expr_unary(cp, k); k->i32 = -k->i32;
|
||||
cp_expr_unary(cp, k); k->i32 = (int32_t)(~(uint32_t)k->i32+1);
|
||||
} else if (cp_opt(cp, '~')) {
|
||||
cp_expr_unary(cp, k); k->i32 = ~k->i32;
|
||||
} else if (cp_opt(cp, '!')) {
|
||||
|
||||
Reference in New Issue
Block a user