lua-users home
lua-l archive

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


I wrote:
> > 4) table.maxn
> 
> Definitely a bug. Patch attached. Thank you!

Ouch, that was too quick. Fixed patch attached.

--Mike
--- a/src/lib_table.c
+++ b/src/lib_table.c
@@ -74,14 +74,14 @@ LJLIB_CF(table_maxn)
   TValue *array = tvref(t->array);
   Node *node;
   lua_Number m = 0;
-  uint32_t i;
-  for (i = 0; i < t->asize; i++)
+  ptrdiff_t i;
+  for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--)
     if (!tvisnil(&array[i])) {
-      m = (lua_Number)i;
+      m = (lua_Number)(int32_t)i;
       break;
     }
   node = noderef(t->node);
-  for (i = 0; i <= t->hmask; i++)
+  for (i = (ptrdiff_t)t->hmask; i >= 0; i--)
     if (tvisnum(&node[i].key) && numV(&node[i].key) > m)
       m = numV(&node[i].key);
   setnumV(L->top-1, m);