diff options
| -rw-r--r-- | bugs | 4 | ||||
| -rw-r--r-- | lbuiltin.c | 16 | ||||
| -rw-r--r-- | lobject.c | 31 |
3 files changed, 27 insertions, 24 deletions
| @@ -118,3 +118,7 @@ Thu Sep 2 10:07:20 EST 1999 | |||
| 118 | could realloc f->consts. | 118 | could realloc f->consts. |
| 119 | (by Supratik Champati; since 3.2 beta) | 119 | (by Supratik Champati; since 3.2 beta) |
| 120 | 120 | ||
| 121 | ** lobject.c / lbuiltin.c | ||
| 122 | Wed Sep 8 17:41:54 EST 1999 | ||
| 123 | >> tonumber'e1' and tonumber(' ', x), for x!=10, gave 0 instead of nil. | ||
| 124 | (since 3.1) | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.61 1999/08/16 20:52:00 roberto Exp roberto $ |
| 3 | ** Built-in functions | 3 | ** Built-in functions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -146,13 +146,15 @@ static void luaB_tonumber (void) { | |||
| 146 | else lua_pushnil(); /* not a number */ | 146 | else lua_pushnil(); /* not a number */ |
| 147 | } | 147 | } |
| 148 | else { | 148 | else { |
| 149 | char *s; | 149 | const char *s1 = luaL_check_string(1); |
| 150 | long n; | 150 | char *s2; |
| 151 | real n; | ||
| 151 | luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); | 152 | luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); |
| 152 | n = strtol(luaL_check_string(1), &s, base); | 153 | n = strtoul(s1, &s2, base); |
| 153 | while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */ | 154 | if (s1 == s2) return; /* no valid digits: return nil */ |
| 154 | if (*s) lua_pushnil(); /* invalid format: return nil */ | 155 | while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */ |
| 155 | else lua_pushnumber(n); | 156 | if (*s2) return; /* invalid trailing character: return nil */ |
| 157 | lua_pushnumber(n); | ||
| 156 | } | 158 | } |
| 157 | } | 159 | } |
| 158 | 160 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.21 1999/09/06 13:55:09 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.22 1999/09/06 20:19:22 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -91,37 +91,34 @@ static double expten (unsigned int e) { | |||
| 91 | int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ | 91 | int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ |
| 92 | double a = 0.0; | 92 | double a = 0.0; |
| 93 | int point = 0; /* number of decimal digits */ | 93 | int point = 0; /* number of decimal digits */ |
| 94 | int sig = 1; | 94 | int sig; |
| 95 | int valid = 0; /* check whether number has at least one valid digit */ | ||
| 96 | while (isspace((unsigned char)*s)) s++; | 95 | while (isspace((unsigned char)*s)) s++; |
| 97 | if (*s == '-') { | 96 | sig = 1; |
| 98 | s++; | 97 | switch (*s) { |
| 99 | sig = -1; | 98 | case '-': sig = -1; /* go through */ |
| 99 | case '+': s++; | ||
| 100 | } | 100 | } |
| 101 | else if (*s == '+') s++; | 101 | if (! (isdigit((unsigned char)*s) || |
| 102 | while (isdigit((unsigned char)*s)) { | 102 | (*s == '.' && isdigit((unsigned char)*(s+1))))) |
| 103 | return 0; /* not (at least one digit before or after the point) */ | ||
| 104 | while (isdigit((unsigned char)*s)) | ||
| 103 | a = 10.0*a + (*(s++)-'0'); | 105 | a = 10.0*a + (*(s++)-'0'); |
| 104 | valid = 1; | ||
| 105 | } | ||
| 106 | if (*s == '.') { | 106 | if (*s == '.') { |
| 107 | s++; | 107 | s++; |
| 108 | while (isdigit((unsigned char)*s)) { | 108 | while (isdigit((unsigned char)*s)) { |
| 109 | a = 10.0*a + (*(s++)-'0'); | 109 | a = 10.0*a + (*(s++)-'0'); |
| 110 | point++; | 110 | point++; |
| 111 | valid = 1; | ||
| 112 | } | 111 | } |
| 113 | } | 112 | } |
| 114 | if (!valid) return 0; | ||
| 115 | a *= sig; | 113 | a *= sig; |
| 116 | if (toupper((unsigned char)*s) == 'E') { | 114 | if (toupper((unsigned char)*s) == 'E') { |
| 117 | int e = 0; | 115 | int e = 0; |
| 118 | sig = 1; | ||
| 119 | s++; | 116 | s++; |
| 120 | if (*s == '-') { | 117 | sig = 1; |
| 121 | s++; | 118 | switch (*s) { |
| 122 | sig = -1; | 119 | case '-': sig = -1; /* go through */ |
| 120 | case '+': s++; | ||
| 123 | } | 121 | } |
| 124 | else if (*s == '+') s++; | ||
| 125 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ | 122 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ |
| 126 | do { | 123 | do { |
| 127 | e = 10*e + (*(s++)-'0'); | 124 | e = 10*e + (*(s++)-'0'); |
