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:
Mike Pall
2022-12-22 00:03:06 +01:00
parent b2791179ef
commit 8a5e398c52
12 changed files with 32 additions and 32 deletions

View File

@@ -205,7 +205,7 @@ static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
else
*up = lj_carith_powu64(u0, u1);
break;
case MM_unm: *up = (uint64_t)-(int64_t)u0; break;
case MM_unm: *up = ~u0+1u; break;
default: lua_assert(0); break;
}
lj_gc_check(L);