summaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-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 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.237 2015/10/29 15:11:41 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.238 2015/11/23 11:31:21 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*/
@@ -1031,15 +1031,18 @@ static int str_format (lua_State *L) {
1031 case 's': { 1031 case 's': {
1032 size_t l; 1032 size_t l;
1033 const char *s = luaL_tolstring(L, arg, &l); 1033 const char *s = luaL_tolstring(L, arg, &l);
1034 luaL_argcheck(L, l == strlen(s), arg, "string cannot contain zeros"); 1034 if (form[2] == '\0') /* no modifiers? */
1035 if (!strchr(form, '.') && l >= 100) { 1035 luaL_addvalue(&b); /* keep entire string */
1036 /* no precision and string is too long to be formatted;
1037 keep original string */
1038 luaL_addvalue(&b);
1039 }
1040 else { 1036 else {
1041 nb = l_sprintf(buff, MAX_ITEM, form, s); 1037 luaL_argcheck(L, l == strlen(s), arg, "string contains zeros");
1042 lua_pop(L, 1); /* remove result from 'luaL_tolstring' */ 1038 if (!strchr(form, '.') && l >= 100) {
1039 /* no precision and string is too long to be formatted */
1040 luaL_addvalue(&b); /* keep entire string */
1041 }
1042 else { /* format the string into 'buff' */
1043 nb = l_sprintf(buff, MAX_ITEM, form, s);
1044 lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
1045 }
1043 } 1046 }
1044 break; 1047 break;
1045 } 1048 }