From cf71a5ddc742692fad813f89f1c9ef53e1ffde0f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 13 Mar 2019 13:16:53 -0300 Subject: Details Several small improvements (code style, warnings, comments, more tests), in particular: - 'lua_topointer' extended to handle strings - raises an error in 'string.format("%10q")' ('%q' with modifiers) - in the manual for 'string.format', the term "option" replaced by "conversion specifier" (the term used by the C standard) --- lstrlib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index 41ebc523..ab4258e5 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -181,7 +181,7 @@ static int str_byte (lua_State *L) { size_t pose = getendpos(L, 3, pi, l); int n, i; if (posi > pose) return 0; /* empty interval; return no values */ - if (pose - posi >= INT_MAX) /* arithmetic overflow? */ + if (pose - posi >= (size_t)INT_MAX) /* arithmetic overflow? */ return luaL_error(L, "string slice too long"); n = (int)(pose - posi) + 1; luaL_checkstack(L, n, "string slice too long"); @@ -1159,7 +1159,7 @@ static int str_format (lua_State *L) { char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */ int nb = 0; /* number of bytes in added item */ if (++arg > top) - luaL_argerror(L, arg, "no value"); + return luaL_argerror(L, arg, "no value"); strfrmt = scanformat(L, strfrmt, form); switch (*strfrmt++) { case 'c': { @@ -1186,6 +1186,8 @@ static int str_format (lua_State *L) { break; } case 'q': { + if (form[2] != '\0') /* modifiers? */ + return luaL_error(L, "specifier '%%q' cannot have modifiers"); addliteral(L, &b, arg); break; } -- cgit v1.2.3-55-g6feb