diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:24:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:24:22 -0300 |
commit | f62565abea4e56f6bd064df83e5b0f3818b99d82 (patch) | |
tree | 564d1f29062842a46baae3f4f371f8c15dd74de5 | |
parent | c9d1d9f9c6ce513c048eb85b99936ee241e5cd3b (diff) | |
download | lua-f62565abea4e56f6bd064df83e5b0f3818b99d82.tar.gz lua-f62565abea4e56f6bd064df83e5b0f3818b99d82.tar.bz2 lua-f62565abea4e56f6bd064df83e5b0f3818b99d82.zip |
avoid warnings with -Wstrict-overflow
-rw-r--r-- | ltable.c | 7 | ||||
-rw-r--r-- | lvm.c | 11 |
2 files changed, 10 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.57 2011/05/31 18:27:56 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.58 2011/06/02 19:31:40 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -88,8 +88,9 @@ static Node *hashnum (const Table *t, lua_Number n) { | |||
88 | int i; | 88 | int i; |
89 | luai_hashnum(i, n); | 89 | luai_hashnum(i, n); |
90 | if (i < 0) { | 90 | if (i < 0) { |
91 | i = -i; /* must be a positive value */ | 91 | if ((unsigned int)i == -(unsigned int)i) |
92 | if (i < 0) i = 0; /* handle INT_MIN */ | 92 | i = 0; /* handle INT_MIN */ |
93 | i = -i; /* must be a positive value */ | ||
93 | } | 94 | } |
94 | return hashmod(t, i); | 95 | return hashmod(t, i); |
95 | } | 96 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.139 2011/05/31 18:27:56 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.140 2011/06/02 19:31:40 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -292,19 +292,20 @@ void luaV_concat (lua_State *L, int total) { | |||
292 | char *buffer; | 292 | char *buffer; |
293 | int i; | 293 | int i; |
294 | /* collect total length */ | 294 | /* collect total length */ |
295 | for (n = 1; n < total && tostring(L, top-n-1); n++) { | 295 | for (i = 1; i < total && tostring(L, top-i-1); i++) { |
296 | size_t l = tsvalue(top-n-1)->len; | 296 | size_t l = tsvalue(top-i-1)->len; |
297 | if (l >= (MAX_SIZET/sizeof(char)) - tl) | 297 | if (l >= (MAX_SIZET/sizeof(char)) - tl) |
298 | luaG_runerror(L, "string length overflow"); | 298 | luaG_runerror(L, "string length overflow"); |
299 | tl += l; | 299 | tl += l; |
300 | } | 300 | } |
301 | buffer = luaZ_openspace(L, &G(L)->buff, tl); | 301 | buffer = luaZ_openspace(L, &G(L)->buff, tl); |
302 | tl = 0; | 302 | tl = 0; |
303 | for (i=n; i>0; i--) { /* concat all strings */ | 303 | n = i; |
304 | do { /* concat all strings */ | ||
304 | size_t l = tsvalue(top-i)->len; | 305 | size_t l = tsvalue(top-i)->len; |
305 | memcpy(buffer+tl, svalue(top-i), l * sizeof(char)); | 306 | memcpy(buffer+tl, svalue(top-i), l * sizeof(char)); |
306 | tl += l; | 307 | tl += l; |
307 | } | 308 | } while (--i > 0); |
308 | setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); | 309 | setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); |
309 | } | 310 | } |
310 | total -= n-1; /* got 'n' strings to create 1 new */ | 311 | total -= n-1; /* got 'n' strings to create 1 new */ |