diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-02-07 11:49:46 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-02-07 11:49:46 -0200 |
commit | b48847c5fac055f0d6120029f6fe1a50c852a8ac (patch) | |
tree | 21ac2ca8e8f9081858e8b6f791a888fe29b099f6 | |
parent | 1143bf92868a9ec47107a302db43a8e5275d8d80 (diff) | |
download | lua-b48847c5fac055f0d6120029f6fe1a50c852a8ac.tar.gz lua-b48847c5fac055f0d6120029f6fe1a50c852a8ac.tar.bz2 lua-b48847c5fac055f0d6120029f6fe1a50c852a8ac.zip |
BUG: "inclinenumber" cannot use public buffer, since it could change
the buffer pointer (luaY_lex and read_long_string have local
pointers to it).
-rw-r--r-- | lex.c | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -1,4 +1,4 @@ | |||
1 | char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.41 1996/11/22 13:08:02 roberto Exp roberto $"; |
2 | 2 | ||
3 | 3 | ||
4 | #include <ctype.h> | 4 | #include <ctype.h> |
@@ -12,7 +12,7 @@ char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $"; | |||
12 | #include "luadebug.h" | 12 | #include "luadebug.h" |
13 | #include "parser.h" | 13 | #include "parser.h" |
14 | 14 | ||
15 | #define MINBUFF 260 | 15 | #define MINBUFF 250 |
16 | 16 | ||
17 | #define next() (current = input()) | 17 | #define next() (current = input()) |
18 | #define save(x) (yytext[tokensize++] = (x)) | 18 | #define save(x) (yytext[tokensize++] = (x)) |
@@ -30,17 +30,22 @@ void lua_setinput (Input fn) | |||
30 | input = fn; | 30 | input = fn; |
31 | } | 31 | } |
32 | 32 | ||
33 | void luaI_syntaxerror (char *s) | 33 | static void luaI_auxsyntaxerror (char *s, char *token) |
34 | { | 34 | { |
35 | char msg[256]; | 35 | char msg[256]; |
36 | char *token = luaI_buffer(1); | ||
37 | if (token[0] == 0) | ||
38 | token = "<eof>"; | ||
39 | sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s", | 36 | sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s", |
40 | s, token, lua_linenumber, lua_parsedfile); | 37 | s, token, lua_linenumber, lua_parsedfile); |
41 | lua_error (msg); | 38 | lua_error (msg); |
42 | } | 39 | } |
43 | 40 | ||
41 | void luaI_syntaxerror (char *s) | ||
42 | { | ||
43 | char *token = luaI_buffer(1); | ||
44 | if (token[0] == 0) | ||
45 | token = "<eof>"; | ||
46 | luaI_auxsyntaxerror(s, token); | ||
47 | } | ||
48 | |||
44 | 49 | ||
45 | static struct | 50 | static struct |
46 | { | 51 | { |
@@ -82,7 +87,7 @@ static int inclinenumber (int pragma_allowed) | |||
82 | { | 87 | { |
83 | ++lua_linenumber; | 88 | ++lua_linenumber; |
84 | if (pragma_allowed && current == '$') { /* is a pragma? */ | 89 | if (pragma_allowed && current == '$') { /* is a pragma? */ |
85 | char *buff = luaI_buffer(MINBUFF+1); | 90 | char buff[MINBUFF+1]; |
86 | int i = 0; | 91 | int i = 0; |
87 | next(); /* skip $ */ | 92 | next(); /* skip $ */ |
88 | while (isalnum((unsigned char)current)) { | 93 | while (isalnum((unsigned char)current)) { |
@@ -95,8 +100,7 @@ static int inclinenumber (int pragma_allowed) | |||
95 | lua_debug = 1; | 100 | lua_debug = 1; |
96 | else if (strcmp(buff, "nodebug") == 0) | 101 | else if (strcmp(buff, "nodebug") == 0) |
97 | lua_debug = 0; | 102 | lua_debug = 0; |
98 | else luaI_syntaxerror("invalid pragma"); | 103 | else luaI_auxsyntaxerror("invalid pragma", buff); |
99 | buff[1] = buff[2] = buff[3] = 0; /* (re)set for next token */ | ||
100 | } | 104 | } |
101 | return lua_linenumber; | 105 | return lua_linenumber; |
102 | } | 106 | } |