lua

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

commit 1aa526263405fb4906eafab3011b13de4e5daf73
parent 07c7fdb9df82c7fc4ae501e21262f781df4ae5e5
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Wed, 30 Jul 2014 10:58:59 -0300

do not assume numbers are coercible to strings

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

diff --git a/lstrlib.c b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.198 2014/04/27 14:42:26 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.199 2014/07/29 16:01:00 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -685,7 +685,8 @@ static int gmatch (lua_State *L) { static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, const char *e) { size_t l, i; - const char *news = lua_tolstring(ms->L, 3, &l); + lua_State *L = ms->L; + const char *news = lua_tolstring(L, 3, &l); for (i = 0; i < l; i++) { if (news[i] != L_ESC) luaL_addchar(b, news[i]); @@ -693,14 +694,16 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, i++; /* skip ESC */ if (!isdigit(uchar(news[i]))) { if (news[i] != L_ESC) - luaL_error(ms->L, "invalid use of " LUA_QL("%c") - " in replacement string", L_ESC); + luaL_error(L, "invalid use of " LUA_QL("%c") + " in replacement string", L_ESC); luaL_addchar(b, news[i]); } else if (news[i] == '0') luaL_addlstring(b, s, e - s); else { push_onecapture(ms, news[i] - '1', s, e); + luaL_tolstring(L, -1, NULL); /* if number, convert it to string */ + lua_remove(L, -2); /* remove original value */ luaL_addvalue(b); /* add capture to accumulated result */ } }