From 7237eb3f1c480d6bc7fe2832ddd36f2137fb69d9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 15 Feb 2024 11:18:34 -0300 Subject: [PATCH] Fixed warnings from different compilers --- lapi.c | 2 +- lauxlib.c | 9 ++++++--- lmathlib.c | 2 +- ltable.c | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lapi.c b/lapi.c index 69b890cd..b2b82cd7 100644 --- a/lapi.c +++ b/lapi.c @@ -1221,7 +1221,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { int param = va_arg(argp, int); int value = va_arg(argp, int); api_check(L, 0 <= param && param < LUA_GCPN, "invalid parameter"); - res = luaO_applyparam(g->gcparams[param], 100); + res = cast_int(luaO_applyparam(g->gcparams[param], 100)); if (value >= 0) g->gcparams[param] = luaO_codeparam(value); break; diff --git a/lauxlib.c b/lauxlib.c index f48060ed..634c85cd 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1131,8 +1131,11 @@ static void warnfon (void *ud, const char *message, int tocont) { /* Size for the buffer in int's, rounded up */ #define BUFSEED ((BUFSEEDB + sizeof(int) - 1) / sizeof(int)) - -#define addbuff(b,v) (memcpy(b, &(v), sizeof(v)), b += sizeof(v)) +/* +** Copy the contents of variable 'v' into the buffer pointed by 'b'. +** (The '&b[0]' disguises 'b' to fix an absurd warning from clang.) +*/ +#define addbuff(b,v) (memcpy(&b[0], &(v), sizeof(v)), b += sizeof(v)) static unsigned int luai_makeseed (void) { @@ -1146,7 +1149,7 @@ static unsigned int luai_makeseed (void) { /* fill (rare but possible) remain of the buffer with zeros */ memset(b, 0, sizeof(buff) - BUFSEEDB); res = buff[0]; - for (i = 0; i < BUFSEED; i++) + for (i = 1; i < BUFSEED; i++) res ^= (res >> 3) + (res << 7) + buff[i]; return res; } diff --git a/lmathlib.c b/lmathlib.c index c0a75f06..c1041f37 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -352,7 +352,7 @@ static lua_Number I2d (Rand64 x) { SRand64 sx = (SRand64)(trim64(x) >> shift64_FIG); lua_Number res = (lua_Number)(sx) * scaleFIG; if (sx < 0) - res += 1.0; /* correct the two's complement if negative */ + res += l_mathop(1.0); /* correct the two's complement if negative */ lua_assert(0 <= res && res < 1); return res; } diff --git a/ltable.c b/ltable.c index dc4621aa..cb7eb648 100644 --- a/ltable.c +++ b/ltable.c @@ -995,7 +995,8 @@ static int finishnodeset (Table *t, const TValue *slot, TValue *val) { } else if (isabstkey(slot)) return HNOTFOUND; /* no slot with that key */ - else return (cast(Node*, slot) - t->node) + HFIRSTNODE; /* node encoded */ + else /* return node encoded */ + return cast_int((cast(Node*, slot) - t->node)) + HFIRSTNODE; }