From b48847c5fac055f0d6120029f6fe1a50c852a8ac Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 7 Feb 1997 11:49:46 -0200 Subject: [PATCH] BUG: "inclinenumber" cannot use public buffer, since it could change the buffer pointer (luaY_lex and read_long_string have local pointers to it). --- lex.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lex.c b/lex.c index 6906037b..aa8bd588 100644 --- a/lex.c +++ b/lex.c @@ -1,4 +1,4 @@ -char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $"; +char *rcs_lex = "$Id: lex.c,v 2.41 1996/11/22 13:08:02 roberto Exp roberto $"; #include @@ -12,7 +12,7 @@ char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $"; #include "luadebug.h" #include "parser.h" -#define MINBUFF 260 +#define MINBUFF 250 #define next() (current = input()) #define save(x) (yytext[tokensize++] = (x)) @@ -30,17 +30,22 @@ void lua_setinput (Input fn) input = fn; } -void luaI_syntaxerror (char *s) +static void luaI_auxsyntaxerror (char *s, char *token) { char msg[256]; - char *token = luaI_buffer(1); - if (token[0] == 0) - token = ""; sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s", s, token, lua_linenumber, lua_parsedfile); lua_error (msg); } +void luaI_syntaxerror (char *s) +{ + char *token = luaI_buffer(1); + if (token[0] == 0) + token = ""; + luaI_auxsyntaxerror(s, token); +} + static struct { @@ -82,7 +87,7 @@ static int inclinenumber (int pragma_allowed) { ++lua_linenumber; if (pragma_allowed && current == '$') { /* is a pragma? */ - char *buff = luaI_buffer(MINBUFF+1); + char buff[MINBUFF+1]; int i = 0; next(); /* skip $ */ while (isalnum((unsigned char)current)) { @@ -95,8 +100,7 @@ static int inclinenumber (int pragma_allowed) lua_debug = 1; else if (strcmp(buff, "nodebug") == 0) lua_debug = 0; - else luaI_syntaxerror("invalid pragma"); - buff[1] = buff[2] = buff[3] = 0; /* (re)set for next token */ + else luaI_auxsyntaxerror("invalid pragma", buff); } return lua_linenumber; }