lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 24359ae2945d0c9bd341598420f5f7678e1d1a03
parent 6c84722afa4f207e14a1fdcd5de1557e9d3ef6f0
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon, 14 Apr 2008 12:54:36 -0300

'string.find' cannot find things after subject's end

Diffstat:
Mlstrlib.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lstrlib.c b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.138 2007/10/29 15:51:10 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.139 2007/11/12 14:10:09 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -499,7 +499,10 @@ static int str_find_aux (lua_State *L, int find) { const char *p = luaL_checklstring(L, 2, &l2); size_t init = posrelat(luaL_optinteger(L, 3, 1), l1); if (init < 1) init = 1; - else if (init > l1) init = l1 + 1; + else if (init > l1 + 1) { /* start after string's end? */ + lua_pushnil(L); /* cannot find anything */ + return 1; + } if (find && (lua_toboolean(L, 4) || /* explicit request? */ strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ /* do a plain search */