diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-15 11:35:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-15 11:35:55 -0300 |
commit | 44b6f496b5eec86795fbf753115b87677087d5b6 (patch) | |
tree | f535db18854928c4fbed7c10e9cabde8cd1c904b | |
parent | fd80e63468f0c08fedd8dbf944fa4954b72d7384 (diff) | |
download | lua-44b6f496b5eec86795fbf753115b87677087d5b6.tar.gz lua-44b6f496b5eec86795fbf753115b87677087d5b6.tar.bz2 lua-44b6f496b5eec86795fbf753115b87677087d5b6.zip |
just in case, avoid side effects in 'ctype' macros
-rw-r--r-- | llex.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -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 | ||
289 | static int readhexaesc (LexState *ls) { | 289 | static 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 | ||
302 | static int readdecesc (LexState *ls) { | 307 | static 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, '\\'); |