aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-20 16:35:36 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-20 16:35:36 -0200
commit76eab106df01013de80033ac07586a79879fca55 (patch)
tree32146d3ac119519d371c14a3318250d09ab5dea9
parent81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a (diff)
downloadlua-76eab106df01013de80033ac07586a79879fca55.tar.gz
lua-76eab106df01013de80033ac07586a79879fca55.tar.bz2
lua-76eab106df01013de80033ac07586a79879fca55.zip
bug: Lexical gets confused with some combination of arithmetic
operators and hexadecimal numbers
-rw-r--r--llex.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/llex.c b/llex.c
index f00e6914..b6874e8c 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp roberto $ 2** $Id: llex.c,v 2.59 2011/11/30 12:43:51 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*/
@@ -222,13 +222,24 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
222 222
223 223
224/* LUA_NUMBER */ 224/* LUA_NUMBER */
225/*
226** this function is quite liberal in what it accepts, as 'luaO_str2d'
227** will reject ill-formed numerals.
228*/
225static void read_numeral (LexState *ls, SemInfo *seminfo) { 229static void read_numeral (LexState *ls, SemInfo *seminfo) {
230 const char *expo = "Ee";
231 int first = ls->current;
226 lua_assert(lisdigit(ls->current)); 232 lua_assert(lisdigit(ls->current));
227 do { 233 save_and_next(ls);
228 save_and_next(ls); 234 if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
229 if (check_next(ls, "EePp")) /* exponent part? */ 235 expo = "Pp";
236 for (;;) {
237 if (check_next(ls, expo)) /* exponent part? */
230 check_next(ls, "+-"); /* optional exponent sign */ 238 check_next(ls, "+-"); /* optional exponent sign */
231 } while (lislalnum(ls->current) || ls->current == '.'); 239 if (lisxdigit(ls->current) || ls->current == '.')
240 save_and_next(ls);
241 else break;
242 }
232 save(ls, '\0'); 243 save(ls, '\0');
233 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ 244 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
234 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ 245 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */