lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Oct 25, 2010 at 7:36 PM, Andre Leiradella <andre@leiradella.com> wrote:
>>> On Mon, Oct 25, 2010 at 1:49 PM, Roberto Ierusalimschy
>>>> Do you know what that means? This is (1<<  (x)), where x is an unsigned
>>>> byte. How shoud I write that to avoid this implicit conversion?
>>
> Maybe a cast to unsigned int will silence the warning?

Details on the warning are here:
http://msdn.microsoft.com/en-us/library/ke55d167(v=VS.100).aspx .  The
below patch makes it happy.  Lua does, however, seem to make some
assumptions that maybe should be stated in the reference manual like
the number of elements in an array fitting in a signed or unsigned
32-bit integer (even on 64-bit).

diff -ur lua-5.1.4/src/lgc.c lua-5.1.4-patched/src/lgc.c
--- lua-5.1.4/src/lgc.c	2007-12-27 08:02:25.000000000 -0500
+++ lua-5.1.4-patched/src/lgc.c	2010-10-25 20:06:22.968889700 -0400
@@ -285,7 +285,7 @@
       if (traversetable(g, h))  /* table is weak? */
         black2gray(o);  /* keep it gray */
       return sizeof(Table) + sizeof(TValue) * h->sizearray +
-                             sizeof(Node) * sizenode(h);
+                             sizeof(Node) * (size_t)sizenode(h);
     }
     case LUA_TFUNCTION: {
       Closure *cl = gco2cl(o);
diff -ur lua-5.1.4/src/ltable.c lua-5.1.4-patched/src/ltable.c
--- lua-5.1.4/src/ltable.c	2007-12-28 10:32:23.000000000 -0500
+++ lua-5.1.4-patched/src/ltable.c	2010-10-25 20:04:14.965568300 -0400
@@ -320,7 +320,7 @@
       setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
   }
   if (nold != dummynode)
-    luaM_freearray(L, nold, twoto(oldhsize), Node);  /* free old array */
+    luaM_freearray(L, nold, (size_t)twoto(oldhsize), Node);  /* free
old array */
 }


@@ -373,7 +373,7 @@

 void luaH_free (lua_State *L, Table *t) {
   if (t->node != dummynode)
-    luaM_freearray(L, t->node, sizenode(t), Node);
+    luaM_freearray(L, t->node, (size_t)sizenode(t), Node);
   luaM_freearray(L, t->array, t->sizearray, TValue);
   luaM_free(L, t);
 }