Roberto Ierusalimschy 26 年之前
父节点
当前提交
0bbd96bd5f
共有 2 个文件被更改,包括 15 次插入12 次删除
  1. 9 9
      lobject.c
  2. 6 3
      lvm.c

+ 9 - 9
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.17 1999/02/12 19:23:02 roberto Exp roberto $
+** $Id: lobject.c,v 1.18 1999/02/26 15:48:30 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -93,25 +93,25 @@ static double expten (unsigned int e) {
 double luaO_str2d (char *s) {  /* LUA_NUMBER */
   double a = 0.0;
   int point = 0;
-  if (!isdigit((unsigned char)*s) && !isdigit((unsigned char)*(s+1)))
-    return -1;  /* no digit before or after decimal point */
   while (isdigit((unsigned char)*s)) {
     a = 10.0*a + (*(s++)-'0');
   }
-  if (*s == '.') s++;
-  while (isdigit((unsigned char)*s)) {
-    a = 10.0*a + (*(s++)-'0');
-    point++;
+  if (*s == '.') {
+    s++;
+    while (isdigit((unsigned char)*s)) {
+      a = 10.0*a + (*(s++)-'0');
+      point++;
+    }
   }
   if (toupper((unsigned char)*s) == 'E') {
     int e = 0;
     int sig = 1;
     s++;
-    if (*s == '+') s++;
-    else if (*s == '-') {
+    if (*s == '-') {
       s++;
       sig = -1;
     }
+    else if (*s == '+') s++;
     if (!isdigit((unsigned char)*s)) return -1;  /* no digit in the exponent? */
     do {
       e = 10*e + (*(s++)-'0');

+ 6 - 3
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 1.53 1999/03/05 21:16:07 roberto Exp roberto $
+** $Id: lvm.c,v 1.54 1999/03/10 14:09:45 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -57,11 +57,14 @@ int luaV_tonumber (TObject *obj) {  /* LUA_NUMBER */
     char *e = svalue(obj);
     int sig = 1;
     while (isspace((unsigned char)*e)) e++;
-    if (*e == '+') e++;
-    else if (*e == '-') {
+    if (*e == '-') {
       e++;
       sig = -1;
     }
+    else if (*e == '+') e++;
+    /* no digit before or after decimal point? */
+    if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1)))
+      return 2;
     t = luaO_str2d(e);
     if (t<0) return 2;
     nvalue(obj) = (real)t*sig;