aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-01-02 09:54:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-01-02 09:54:14 -0200
commit24434b59f79975bcca9a15e7bc55d5cab7984bbe (patch)
tree910f1502555a7e306f4a793ca843791122616380
parentbeb2aa5a46d0f0a8464f4045b1cfb790e97f08c7 (diff)
downloadlua-24434b59f79975bcca9a15e7bc55d5cab7984bbe.tar.gz
lua-24434b59f79975bcca9a15e7bc55d5cab7984bbe.tar.bz2
lua-24434b59f79975bcca9a15e7bc55d5cab7984bbe.zip
'%' must be '%%' to avoid formatting problems
-rw-r--r--lstrlib.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lstrlib.c b/lstrlib.c
index e239e2fb..5a3c8ea4 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.99 2003/05/14 14:35:54 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.100 2003/10/07 20:13:41 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*/
@@ -200,7 +200,7 @@ static const char *luaI_classend (MatchState *ms, const char *p) {
200 switch (*p++) { 200 switch (*p++) {
201 case ESC: { 201 case ESC: {
202 if (*p == '\0') 202 if (*p == '\0')
203 luaL_error(ms->L, "malformed pattern (ends with `%')"); 203 luaL_error(ms->L, "malformed pattern (ends with `%%')");
204 return p+1; 204 return p+1;
205 } 205 }
206 case '[': { 206 case '[': {
@@ -682,7 +682,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt,
682 luaL_error(L, "invalid format (width or precision too long)"); 682 luaL_error(L, "invalid format (width or precision too long)");
683 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ 683 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
684 luaL_error(L, "invalid format (too long)"); 684 luaL_error(L, "invalid format (too long)");
685 form[0] = '%'; 685 form[0] = ESC;
686 strncpy(form+1, strfrmt, p-strfrmt+1); 686 strncpy(form+1, strfrmt, p-strfrmt+1);
687 form[p-strfrmt+2] = 0; 687 form[p-strfrmt+2] = 0;
688 return p; 688 return p;
@@ -697,9 +697,9 @@ static int str_format (lua_State *L) {
697 luaL_Buffer b; 697 luaL_Buffer b;
698 luaL_buffinit(L, &b); 698 luaL_buffinit(L, &b);
699 while (strfrmt < strfrmt_end) { 699 while (strfrmt < strfrmt_end) {
700 if (*strfrmt != '%') 700 if (*strfrmt != ESC)
701 luaL_putchar(&b, *strfrmt++); 701 luaL_putchar(&b, *strfrmt++);
702 else if (*++strfrmt == '%') 702 else if (*++strfrmt == ESC)
703 luaL_putchar(&b, *strfrmt++); /* %% */ 703 luaL_putchar(&b, *strfrmt++); /* %% */
704 else { /* format item */ 704 else { /* format item */
705 char form[MAX_FORMAT]; /* to store the format (`%...') */ 705 char form[MAX_FORMAT]; /* to store the format (`%...') */