diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-07-27 09:13:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-07-27 09:13:08 -0300 |
commit | 03a078493ebfb9a85aea44594ca3a90f9d297f85 (patch) | |
tree | f62338a0358259fb3cdd40e472070663ac47c215 | |
parent | bae57ea088504146883323c1bc122a74b34760c3 (diff) | |
download | lua-03a078493ebfb9a85aea44594ca3a90f9d297f85.tar.gz lua-03a078493ebfb9a85aea44594ca3a90f9d297f85.tar.bz2 lua-03a078493ebfb9a85aea44594ca3a90f9d297f85.zip |
refuse things like 'inf' or 'Nan' as numerals
-rw-r--r-- | lobject.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.51 2011/06/23 16:01:06 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.53 2011/07/27 12:09:13 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 | */ |
@@ -103,8 +103,8 @@ static int isneg (const char **s) { | |||
103 | 103 | ||
104 | 104 | ||
105 | static lua_Number readhexa (const char **s, lua_Number r, int *count) { | 105 | static lua_Number readhexa (const char **s, lua_Number r, int *count) { |
106 | while (lisxdigit(cast_uchar(**s))) { /* read integer part */ | 106 | for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */ |
107 | r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++))); | 107 | r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(**s))); |
108 | (*count)++; | 108 | (*count)++; |
109 | } | 109 | } |
110 | return r; | 110 | return r; |
@@ -157,7 +157,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
157 | 157 | ||
158 | int luaO_str2d (const char *s, size_t len, lua_Number *result) { | 158 | int luaO_str2d (const char *s, size_t len, lua_Number *result) { |
159 | char *endptr; | 159 | char *endptr; |
160 | if (strpbrk(s, "xX")) /* hexa? */ | 160 | if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ |
161 | return 0; | ||
162 | else if (strpbrk(s, "xX")) /* hexa? */ | ||
161 | *result = lua_strx2number(s, &endptr); | 163 | *result = lua_strx2number(s, &endptr); |
162 | else | 164 | else |
163 | *result = lua_str2number(s, &endptr); | 165 | *result = lua_str2number(s, &endptr); |