diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:22:47 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:22:47 -0300 |
commit | c9d1d9f9c6ce513c048eb85b99936ee241e5cd3b (patch) | |
tree | 51f1de8db6b7d95e72653578917a159408a17dee | |
parent | 35391d9b1aab036f37799458236e0ea0ca4a4d3f (diff) | |
download | lua-c9d1d9f9c6ce513c048eb85b99936ee241e5cd3b.tar.gz lua-c9d1d9f9c6ce513c048eb85b99936ee241e5cd3b.tar.bz2 lua-c9d1d9f9c6ce513c048eb85b99936ee241e5cd3b.zip |
better way to test overflows with string indices
-rw-r--r-- | lstrlib.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.166 2011/04/20 16:36:28 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.167 2011/05/03 16:01:57 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 | */ |
@@ -45,7 +45,7 @@ static int str_len (lua_State *L) { | |||
45 | /* translate a relative string position: negative means back from end */ | 45 | /* translate a relative string position: negative means back from end */ |
46 | static size_t posrelat (ptrdiff_t pos, size_t len) { | 46 | static size_t posrelat (ptrdiff_t pos, size_t len) { |
47 | if (pos >= 0) return (size_t)pos; | 47 | if (pos >= 0) return (size_t)pos; |
48 | else if (pos == -pos || (size_t)-pos > len) return 0; | 48 | else if (-(size_t)pos > len) return 0; |
49 | else return len - ((size_t)-pos) + 1; | 49 | else return len - ((size_t)-pos) + 1; |
50 | } | 50 | } |
51 | 51 | ||