mirror of
https://github.com/lua/lua.git
synced 2024-11-23 18:23:43 +08:00
do not convert decimal constants with overflow to integers.
(Therefore, they will be converted as floats)
This commit is contained in:
parent
4d5ab9baa6
commit
10b0b09555
10
lobject.c
10
lobject.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.c,v 2.109 2015/12/14 11:53:27 roberto Exp roberto $
|
||||
** $Id: lobject.c,v 2.110 2016/05/02 14:00:32 roberto Exp roberto $
|
||||
** Some generic functions over Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -293,6 +293,9 @@ static const char *l_str2d (const char *s, lua_Number *result) {
|
||||
}
|
||||
|
||||
|
||||
#define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10)
|
||||
#define MAXLASTD cast_int(LUA_MAXINTEGER % 10)
|
||||
|
||||
static const char *l_str2int (const char *s, lua_Integer *result) {
|
||||
lua_Unsigned a = 0;
|
||||
int empty = 1;
|
||||
@ -309,7 +312,10 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
|
||||
}
|
||||
else { /* decimal */
|
||||
for (; lisdigit(cast_uchar(*s)); s++) {
|
||||
a = a * 10 + *s - '0';
|
||||
int d = *s - '0';
|
||||
if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
|
||||
return NULL; /* do not accept it (as integer) */
|
||||
a = a * 10 + d;
|
||||
empty = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user