aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-14 12:54:59 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-14 12:54:59 -0300
commit24359ae2945d0c9bd341598420f5f7678e1d1a03 (patch)
tree678683f8b46143db2ca309bad93a1f8864e3db13
parent6c84722afa4f207e14a1fdcd5de1557e9d3ef6f0 (diff)
downloadlua-24359ae2945d0c9bd341598420f5f7678e1d1a03.tar.gz
lua-24359ae2945d0c9bd341598420f5f7678e1d1a03.tar.bz2
lua-24359ae2945d0c9bd341598420f5f7678e1d1a03.zip
'string.find' cannot find things after subject's end
-rw-r--r--lstrlib.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 0300923f..338d81ec 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -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 */