From 03a078493ebfb9a85aea44594ca3a90f9d297f85 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 27 Jul 2011 09:13:08 -0300 Subject: [PATCH] refuse things like 'inf' or 'Nan' as numerals --- lobject.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lobject.c b/lobject.c index 54c82d2c..fdbf7f76 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.51 2011/06/23 16:01:06 roberto Exp roberto $ +** $Id: lobject.c,v 2.53 2011/07/27 12:09:13 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -103,8 +103,8 @@ static int isneg (const char **s) { static lua_Number readhexa (const char **s, lua_Number r, int *count) { - while (lisxdigit(cast_uchar(**s))) { /* read integer part */ - r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++))); + for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */ + r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(**s))); (*count)++; } return r; @@ -157,7 +157,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { int luaO_str2d (const char *s, size_t len, lua_Number *result) { char *endptr; - if (strpbrk(s, "xX")) /* hexa? */ + if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ + return 0; + else if (strpbrk(s, "xX")) /* hexa? */ *result = lua_strx2number(s, &endptr); else *result = lua_str2number(s, &endptr);