diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-04-14 12:54:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-04-14 12:54:59 -0300 |
commit | 24359ae2945d0c9bd341598420f5f7678e1d1a03 (patch) | |
tree | 678683f8b46143db2ca309bad93a1f8864e3db13 | |
parent | 6c84722afa4f207e14a1fdcd5de1557e9d3ef6f0 (diff) | |
download | lua-24359ae2945d0c9bd341598420f5f7678e1d1a03.tar.gz lua-24359ae2945d0c9bd341598420f5f7678e1d1a03.tar.bz2 lua-24359ae2945d0c9bd341598420f5f7678e1d1a03.zip |
'string.find' cannot find things after subject's end
-rw-r--r-- | lstrlib.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.138 2007/10/29 15:51:10 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.139 2007/11/12 14:10:09 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 | */ |
@@ -499,7 +499,10 @@ static int str_find_aux (lua_State *L, int find) { | |||
499 | const char *p = luaL_checklstring(L, 2, &l2); | 499 | const char *p = luaL_checklstring(L, 2, &l2); |
500 | size_t init = posrelat(luaL_optinteger(L, 3, 1), l1); | 500 | size_t init = posrelat(luaL_optinteger(L, 3, 1), l1); |
501 | if (init < 1) init = 1; | 501 | if (init < 1) init = 1; |
502 | else if (init > l1) init = l1 + 1; | 502 | else if (init > l1 + 1) { /* start after string's end? */ |
503 | lua_pushnil(L); /* cannot find anything */ | ||
504 | return 1; | ||
505 | } | ||
503 | if (find && (lua_toboolean(L, 4) || /* explicit request? */ | 506 | if (find && (lua_toboolean(L, 4) || /* explicit request? */ |
504 | strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ | 507 | strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ |
505 | /* do a plain search */ | 508 | /* do a plain search */ |