Pārlūkot izejas kodu

bug: Lexical gets confused with some combination of arithmetic
operators and hexadecimal numbers

Roberto Ierusalimschy 13 gadi atpakaļ
vecāks
revīzija
76eab106df
1 mainītis faili ar 16 papildinājumiem un 5 dzēšanām
  1. 16 5
      llex.c

+ 16 - 5
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp roberto $
+** $Id: llex.c,v 2.59 2011/11/30 12:43:51 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -222,13 +222,24 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
 
 
 /* LUA_NUMBER */
+/*
+** this function is quite liberal in what it accepts, as 'luaO_str2d'
+** will reject ill-formed numerals.
+*/
 static void read_numeral (LexState *ls, SemInfo *seminfo) {
+  const char *expo = "Ee";
+  int first = ls->current;
   lua_assert(lisdigit(ls->current));
-  do {
-    save_and_next(ls);
-    if (check_next(ls, "EePp"))  /* exponent part? */
+  save_and_next(ls);
+  if (first == '0' && check_next(ls, "Xx"))  /* hexadecimal? */
+    expo = "Pp";
+  for (;;) {
+    if (check_next(ls, expo))  /* exponent part? */
       check_next(ls, "+-");  /* optional exponent sign */
-  } while (lislalnum(ls->current) || ls->current == '.');
+    if (lisxdigit(ls->current) || ls->current == '.')
+      save_and_next(ls);
+    else  break;
+  }
   save(ls, '\0');
   buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */
   if (!buff2d(ls->buff, &seminfo->r))  /* format error? */