aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-06-15 11:35:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-06-15 11:35:55 -0300
commit44b6f496b5eec86795fbf753115b87677087d5b6 (patch)
treef535db18854928c4fbed7c10e9cabde8cd1c904b
parentfd80e63468f0c08fedd8dbf944fa4954b72d7384 (diff)
downloadlua-44b6f496b5eec86795fbf753115b87677087d5b6.tar.gz
lua-44b6f496b5eec86795fbf753115b87677087d5b6.tar.bz2
lua-44b6f496b5eec86795fbf753115b87677087d5b6.zip
just in case, avoid side effects in 'ctype' macros
-rw-r--r--llex.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/llex.c b/llex.c
index 51f22554..9d36ad33 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.46 2011/02/23 13:13:10 roberto Exp roberto $ 2** $Id: llex.c,v 2.47 2011/05/03 15:51:16 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -287,25 +287,32 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
287 287
288 288
289static int readhexaesc (LexState *ls) { 289static int readhexaesc (LexState *ls) {
290 int c1, c2 = EOZ; 290 int c1 = next(ls);
291 if (!lisxdigit(c1 = next(ls)) || !lisxdigit(c2 = next(ls))) { 291 int c2 = EOZ;
292 luaZ_resetbuffer(ls->buff); /* prepare error message */ 292 if (lisxdigit(c1)) {
293 save(ls, '\\'); save(ls, 'x'); 293 c2 = next(ls);
294 if (c1 != EOZ) save(ls, c1); 294 if (lisxdigit(c2))
295 if (c2 != EOZ) save(ls, c2); 295 return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2);
296 lexerror(ls, "hexadecimal digit expected", TK_STRING); 296 /* else go through to error */
297 } 297 }
298 return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2); 298 luaZ_resetbuffer(ls->buff); /* prepare error message */
299 save(ls, '\\'); save(ls, 'x');
300 if (c1 != EOZ) save(ls, c1);
301 if (c2 != EOZ) save(ls, c2);
302 lexerror(ls, "hexadecimal digit expected", TK_STRING);
303 return 0; /* to avoid warnings */
299} 304}
300 305
301 306
302static int readdecesc (LexState *ls) { 307static int readdecesc (LexState *ls) {
303 int c1 = ls->current, c2, c3; 308 int c1 = ls->current; /* first char must be a digit */
304 int c = c1 - '0'; 309 int c2 = next(ls); /* read second char */
305 if (lisdigit(c2 = next(ls))) { 310 int c = c1 - '0'; /* partial result */
306 c = 10*c + c2 - '0'; 311 if (lisdigit(c2)) {
307 if (lisdigit(c3 = next(ls))) { 312 int c3 = next(ls); /* read third char */
308 c = 10*c + c3 - '0'; 313 c = 10*c + c2 - '0'; /* update result */
314 if (lisdigit(c3)) {
315 c = 10*c + c3 - '0'; /* update result */
309 if (c > UCHAR_MAX) { 316 if (c > UCHAR_MAX) {
310 luaZ_resetbuffer(ls->buff); /* prepare error message */ 317 luaZ_resetbuffer(ls->buff); /* prepare error message */
311 save(ls, '\\'); 318 save(ls, '\\');