diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-03-14 15:59:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-03-14 15:59:53 -0300 |
commit | d8a3a00d8481a13a94247c3dc33f43ebf3569e0b (patch) | |
tree | bcf9577770b8fd912e9e5aa1cead1adf5f49efa4 | |
parent | c9ea94ec92a8dc02ff689aea3485c891780128b9 (diff) | |
download | lua-d8a3a00d8481a13a94247c3dc33f43ebf3569e0b.tar.gz lua-d8a3a00d8481a13a94247c3dc33f43ebf3569e0b.tar.bz2 lua-d8a3a00d8481a13a94247c3dc33f43ebf3569e0b.zip |
`string.find' also accepts out-of-range indices
-rw-r--r-- | lstrlib.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.94 2003/02/12 09:10:41 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.95 2003/03/11 12:24:34 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 | */ |
@@ -478,7 +478,8 @@ static int str_find (lua_State *L) { | |||
478 | const char *s = luaL_checklstring(L, 1, &l1); | 478 | const char *s = luaL_checklstring(L, 1, &l1); |
479 | const char *p = luaL_checklstring(L, 2, &l2); | 479 | const char *p = luaL_checklstring(L, 2, &l2); |
480 | sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1; | 480 | sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1; |
481 | luaL_argcheck(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range"); | 481 | if (init < 0) init = 0; |
482 | else if ((size_t)(init) > l1) init = l1; | ||
482 | if (lua_toboolean(L, 4) || /* explicit request? */ | 483 | if (lua_toboolean(L, 4) || /* explicit request? */ |
483 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ | 484 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
484 | /* do a plain search */ | 485 | /* do a plain search */ |