]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Prevent sanitizer warnings for lj_tab_new*() and table.new().
authorMike Pall <mike>
Sun, 24 May 2026 23:28:32 +0000 (01:28 +0200)
committerMike Pall <mike>
Sun, 24 May 2026 23:28:32 +0000 (01:28 +0200)
Reported by Sergey Bronnikov. #1458

src/lj_api.c
src/lj_tab.c
src/lj_tab.h

index 6369c17db697580b8890c04b1caf154ddcb8c0bd..f972a760b9e020be983c161bcfb38443c8ea0a80 100644 (file)
@@ -708,7 +708,7 @@ LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
 LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
 {
   lj_gc_check(L);
-  settabV(L, L->top, lj_tab_new_ah(L, narray, nrec));
+  settabV(L, L->top, lj_tab_new_ah(L, (uint32_t)narray, (uint32_t)nrec));
   incr_top(L);
 }
 
index c63117fa426dc59b63fc6a42688ff49265bfc239..f9dd541be99a357d1bb9531f6f115edf763d015b 100644 (file)
@@ -145,9 +145,9 @@ GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits)
 }
 
 /* The API of this function conforms to lua_createtable(). */
-GCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h)
+GCtab *lj_tab_new_ah(lua_State *L, uint32_t a, uint32_t h)
 {
-  return lj_tab_new(L, (uint32_t)(a > 0 ? a+1 : 0), hsize2hbits(h));
+  return lj_tab_new(L, a ? a+1 : 0, hsize2hbits(h));
 }
 
 #if LJ_HASJIT
index f1712e45f824cc58fe65d8b911c1f747b523ce1f..9822c3266ba81db49078e2ed9d5821b8f857ddfa 100644 (file)
@@ -53,7 +53,7 @@ static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash)
 #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)
 
 LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);
-LJ_FUNC GCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h);
+LJ_FUNC GCtab *lj_tab_new_ah(lua_State *L, uint32_t a, uint32_t h);
 #if LJ_HASJIT
 LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);
 #endif