diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-03-28 16:14:47 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-03-28 16:14:47 -0300 |
| commit | e723c75c02a48d0c766f1f30f7a321f7fdb239dc (patch) | |
| tree | aa3f11828e25ccf2dc02d077e59ee12a4313a3bd /lstrlib.c | |
| parent | b436ed58a3416c2e1936bdce880ac09925401a87 (diff) | |
| download | lua-e723c75c02a48d0c766f1f30f7a321f7fdb239dc.tar.gz lua-e723c75c02a48d0c766f1f30f7a321f7fdb239dc.tar.bz2 lua-e723c75c02a48d0c766f1f30f7a321f7fdb239dc.zip | |
details (avoid 'lint' warnings)
Diffstat (limited to 'lstrlib.c')
| -rw-r--r-- | lstrlib.c | 24 |
1 files changed, 12 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.225 2015/02/05 17:50:24 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.226 2015/02/09 18:05:46 roberto Exp roberto $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -70,7 +70,7 @@ static int str_sub (lua_State *L) { | |||
| 70 | if (start < 1) start = 1; | 70 | if (start < 1) start = 1; |
| 71 | if (end > (lua_Integer)l) end = l; | 71 | if (end > (lua_Integer)l) end = l; |
| 72 | if (start <= end) | 72 | if (start <= end) |
| 73 | lua_pushlstring(L, s + start - 1, (size_t)(end - start + 1)); | 73 | lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1); |
| 74 | else lua_pushliteral(L, ""); | 74 | else lua_pushliteral(L, ""); |
| 75 | return 1; | 75 | return 1; |
| 76 | } | 76 | } |
| @@ -149,9 +149,9 @@ static int str_byte (lua_State *L) { | |||
| 149 | if (posi < 1) posi = 1; | 149 | if (posi < 1) posi = 1; |
| 150 | if (pose > (lua_Integer)l) pose = l; | 150 | if (pose > (lua_Integer)l) pose = l; |
| 151 | if (posi > pose) return 0; /* empty interval; return no values */ | 151 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 152 | n = (int)(pose - posi + 1); | 152 | if (pose - posi >= INT_MAX) /* arithmetic overflow? */ |
| 153 | if (posi + n <= pose) /* arithmetic overflow? */ | ||
| 154 | return luaL_error(L, "string slice too long"); | 153 | return luaL_error(L, "string slice too long"); |
| 154 | n = (int)(pose - posi) + 1; | ||
| 155 | luaL_checkstack(L, n, "string slice too long"); | 155 | luaL_checkstack(L, n, "string slice too long"); |
| 156 | for (i=0; i<n; i++) | 156 | for (i=0; i<n; i++) |
| 157 | lua_pushinteger(L, uchar(s[posi+i-1])); | 157 | lua_pushinteger(L, uchar(s[posi+i-1])); |
| @@ -499,7 +499,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 499 | } | 499 | } |
| 500 | case '+': /* 1 or more repetitions */ | 500 | case '+': /* 1 or more repetitions */ |
| 501 | s++; /* 1 match already done */ | 501 | s++; /* 1 match already done */ |
| 502 | /* go through */ | 502 | /* FALLTHROUGH */ |
| 503 | case '*': /* 0 or more repetitions */ | 503 | case '*': /* 0 or more repetitions */ |
| 504 | s = max_expand(ms, s, p, ep); | 504 | s = max_expand(ms, s, p, ep); |
| 505 | break; | 505 | break; |
| @@ -554,7 +554,7 @@ static void push_onecapture (MatchState *ms, int i, const char *s, | |||
| 554 | ptrdiff_t l = ms->capture[i].len; | 554 | ptrdiff_t l = ms->capture[i].len; |
| 555 | if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); | 555 | if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); |
| 556 | if (l == CAP_POSITION) | 556 | if (l == CAP_POSITION) |
| 557 | lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); | 557 | lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1); |
| 558 | else | 558 | else |
| 559 | lua_pushlstring(ms->L, ms->capture[i].init, l); | 559 | lua_pushlstring(ms->L, ms->capture[i].init, l); |
| 560 | } | 560 | } |
| @@ -598,8 +598,8 @@ static int str_find_aux (lua_State *L, int find) { | |||
| 598 | /* do a plain search */ | 598 | /* do a plain search */ |
| 599 | const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp); | 599 | const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp); |
| 600 | if (s2) { | 600 | if (s2) { |
| 601 | lua_pushinteger(L, s2 - s + 1); | 601 | lua_pushinteger(L, (s2 - s) + 1); |
| 602 | lua_pushinteger(L, s2 - s + lp); | 602 | lua_pushinteger(L, (s2 - s) + lp); |
| 603 | return 2; | 603 | return 2; |
| 604 | } | 604 | } |
| 605 | } | 605 | } |
| @@ -621,7 +621,7 @@ static int str_find_aux (lua_State *L, int find) { | |||
| 621 | lua_assert(ms.matchdepth == MAXCCALLS); | 621 | lua_assert(ms.matchdepth == MAXCCALLS); |
| 622 | if ((res=match(&ms, s1, p)) != NULL) { | 622 | if ((res=match(&ms, s1, p)) != NULL) { |
| 623 | if (find) { | 623 | if (find) { |
| 624 | lua_pushinteger(L, s1 - s + 1); /* start */ | 624 | lua_pushinteger(L, (s1 - s) + 1); /* start */ |
| 625 | lua_pushinteger(L, res - s); /* end */ | 625 | lua_pushinteger(L, res - s); /* end */ |
| 626 | return push_captures(&ms, NULL, 0) + 2; | 626 | return push_captures(&ms, NULL, 0) + 2; |
| 627 | } | 627 | } |
| @@ -935,8 +935,8 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { | |||
| 935 | if (isdigit(uchar(*p))) | 935 | if (isdigit(uchar(*p))) |
| 936 | luaL_error(L, "invalid format (width or precision too long)"); | 936 | luaL_error(L, "invalid format (width or precision too long)"); |
| 937 | *(form++) = '%'; | 937 | *(form++) = '%'; |
| 938 | memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char)); | 938 | memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char)); |
| 939 | form += p - strfrmt + 1; | 939 | form += (p - strfrmt) + 1; |
| 940 | *form = '\0'; | 940 | *form = '\0'; |
| 941 | return p; | 941 | return p; |
| 942 | } | 942 | } |
| @@ -1335,7 +1335,7 @@ static int str_pack (lua_State *L) { | |||
| 1335 | totalsize += len + 1; | 1335 | totalsize += len + 1; |
| 1336 | break; | 1336 | break; |
| 1337 | } | 1337 | } |
| 1338 | case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* go through */ | 1338 | case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* FALLTHROUGH */ |
| 1339 | case Kpaddalign: case Knop: | 1339 | case Kpaddalign: case Knop: |
| 1340 | arg--; /* undo increment */ | 1340 | arg--; /* undo increment */ |
| 1341 | break; | 1341 | break; |
