aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-05-20 11:07:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-05-20 11:07:48 -0300
commit10b0b09555920ad2ac186274348e73ed61cede90 (patch)
tree46d5fc5e9d37d59f01c15a2b21971aec6df19c6e /lobject.c
parent4d5ab9baa64f671b3b0c030821c9502302937dc9 (diff)
downloadlua-10b0b09555920ad2ac186274348e73ed61cede90.tar.gz
lua-10b0b09555920ad2ac186274348e73ed61cede90.tar.bz2
lua-10b0b09555920ad2ac186274348e73ed61cede90.zip
do not convert decimal constants with overflow to integers.
(Therefore, they will be converted as floats)
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lobject.c b/lobject.c
index 41a50df1..6c72144a 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.109 2015/12/14 11:53:27 roberto Exp roberto $ 2** $Id: lobject.c,v 2.110 2016/05/02 14:00:32 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*/
@@ -293,6 +293,9 @@ static const char *l_str2d (const char *s, lua_Number *result) {
293} 293}
294 294
295 295
296#define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10)
297#define MAXLASTD cast_int(LUA_MAXINTEGER % 10)
298
296static const char *l_str2int (const char *s, lua_Integer *result) { 299static const char *l_str2int (const char *s, lua_Integer *result) {
297 lua_Unsigned a = 0; 300 lua_Unsigned a = 0;
298 int empty = 1; 301 int empty = 1;
@@ -309,7 +312,10 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
309 } 312 }
310 else { /* decimal */ 313 else { /* decimal */
311 for (; lisdigit(cast_uchar(*s)); s++) { 314 for (; lisdigit(cast_uchar(*s)); s++) {
312 a = a * 10 + *s - '0'; 315 int d = *s - '0';
316 if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
317 return NULL; /* do not accept it (as integer) */
318 a = a * 10 + d;
313 empty = 0; 319 empty = 0;
314 } 320 }
315 } 321 }