summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-25 14:28:17 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-25 14:28:17 -0200
commitc25d59a6bdbc6f587310159a1975b399ad8dd079 (patch)
treebdf3a658d7745416f497e035351e2fcca48e3380
parent5936eb16d8d6224b0b3605abb77e90ddf1ccc0db (diff)
downloadlua-github-5-3-2.tar.gz
format "%s" in 'string.format' accepts embedded zeros when itv5.3.2v5-3-2
has no modifiers
-rw-r--r--lstrlib.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 1bc26829..a43c4a82 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.237 2015/10/29 15:11:41 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.238 2015/11/23 11:31:21 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -1031,15 +1031,18 @@ static int str_format (lua_State *L) {
case 's': {
size_t l;
const char *s = luaL_tolstring(L, arg, &l);
- luaL_argcheck(L, l == strlen(s), arg, "string cannot contain zeros");
- if (!strchr(form, '.') && l >= 100) {
- /* no precision and string is too long to be formatted;
- keep original string */
- luaL_addvalue(&b);
- }
+ if (form[2] == '\0') /* no modifiers? */
+ luaL_addvalue(&b); /* keep entire string */
else {
- nb = l_sprintf(buff, MAX_ITEM, form, s);
- lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ luaL_argcheck(L, l == strlen(s), arg, "string contains zeros");
+ if (!strchr(form, '.') && l >= 100) {
+ /* no precision and string is too long to be formatted */
+ luaL_addvalue(&b); /* keep entire string */
+ }
+ else { /* format the string into 'buff' */
+ nb = l_sprintf(buff, MAX_ITEM, form, s);
+ lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ }
}
break;
}