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:
@@ -577,7 +577,7 @@ GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned)
|
||||
if (isunsigned) {
|
||||
*--p = 'U';
|
||||
} else if ((int64_t)n < 0) {
|
||||
n = (uint64_t)-(int64_t)n;
|
||||
n = ~n+1u;
|
||||
sign = 1;
|
||||
}
|
||||
do { *--p = (char)('0' + n % 10); } while (n /= 10);
|
||||
|
||||
Reference in New Issue
Block a user