浏览代码

avoid warnings with -Wstrict-overflow

Roberto Ierusalimschy 14 年之前
父节点
当前提交
f62565abea
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 4 3
      ltable.c
  2. 6 5
      lvm.c

+ 4 - 3
ltable.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltable.c,v 2.57 2011/05/31 18:27:56 roberto Exp roberto $
+** $Id: ltable.c,v 2.58 2011/06/02 19:31:40 roberto Exp roberto $
 ** Lua tables (hash)
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -88,8 +88,9 @@ static Node *hashnum (const Table *t, lua_Number n) {
   int i;
   int i;
   luai_hashnum(i, n);
   luai_hashnum(i, n);
   if (i < 0) {
   if (i < 0) {
-     i = -i;  /* must be a positive value */
-     if (i < 0) i = 0;  /* handle INT_MIN */
+    if ((unsigned int)i == -(unsigned int)i)
+      i = 0;  /* handle INT_MIN */
+    i = -i;  /* must be a positive value */
   }
   }
   return hashmod(t, i);
   return hashmod(t, i);
 }
 }

+ 6 - 5
lvm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lvm.c,v 2.139 2011/05/31 18:27:56 roberto Exp roberto $
+** $Id: lvm.c,v 2.140 2011/06/02 19:31:40 roberto Exp roberto $
 ** Lua virtual machine
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -292,19 +292,20 @@ void luaV_concat (lua_State *L, int total) {
       char *buffer;
       char *buffer;
       int i;
       int i;
       /* collect total length */
       /* collect total length */
-      for (n = 1; n < total && tostring(L, top-n-1); n++) {
-        size_t l = tsvalue(top-n-1)->len;
+      for (i = 1; i < total && tostring(L, top-i-1); i++) {
+        size_t l = tsvalue(top-i-1)->len;
         if (l >= (MAX_SIZET/sizeof(char)) - tl)
         if (l >= (MAX_SIZET/sizeof(char)) - tl)
           luaG_runerror(L, "string length overflow");
           luaG_runerror(L, "string length overflow");
         tl += l;
         tl += l;
       }
       }
       buffer = luaZ_openspace(L, &G(L)->buff, tl);
       buffer = luaZ_openspace(L, &G(L)->buff, tl);
       tl = 0;
       tl = 0;
-      for (i=n; i>0; i--) {  /* concat all strings */
+      n = i;
+      do {  /* concat all strings */
         size_t l = tsvalue(top-i)->len;
         size_t l = tsvalue(top-i)->len;
         memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
         memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
         tl += l;
         tl += l;
-      }
+      } while (--i > 0);
       setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
       setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
     }
     }
     total -= n-1;  /* got 'n' strings to create 1 new */
     total -= n-1;  /* got 'n' strings to create 1 new */