diff options
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/manual.html | 10 | ||||
-rw-r--r-- | src/lobject.c | 10 | ||||
-rw-r--r-- | src/lstrlib.c | 33 | ||||
-rw-r--r-- | src/lua.h | 4 |
5 files changed, 36 insertions, 23 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.3.3, released on 18 May 2016. +This is Lua 5.3.3, released on 30 May 2016. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/manual.html b/doc/manual.html index 6baf87f9..5fb26b23 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -35,7 +35,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> -<!-- $Id: manual.of,v 1.161 2016/05/18 18:20:41 roberto Exp $ --> +<!-- $Id: manual.of,v 1.162 2016/05/30 15:57:03 roberto Exp $ --> @@ -1179,7 +1179,7 @@ and the system file functions may have problems with some control characters. So, it is safer to represent non-text data as a quoted literal with -explicit escape sequences for non-text characters. +explicit escape sequences for the non-text characters. <p> @@ -1214,7 +1214,9 @@ plus an optional binary exponent, marked by a letter '<code>p</code>' or '<code>P</code>'. A numeric constant with a radix point or an exponent denotes a float; -otherwise it denotes an integer. +otherwise, +if its value fits in an integer, +it denotes an integer. Examples of valid integer constants are <pre> @@ -10898,7 +10900,7 @@ and LiteralString, see <a href="#3.1">§3.1</a>.) <P CLASS="footer"> Last update: -Wed May 18 18:55:35 BRT 2016 +Mon May 30 13:11:08 BRT 2016 </P> <!-- Last change: revised for Lua 5.3.3 diff --git a/src/lobject.c b/src/lobject.c index 04f45da2..a44b3850 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.110 2016/05/02 14:00:32 roberto Exp $ +** $Id: lobject.c,v 2.111 2016/05/20 14:07:48 roberto Exp $ ** 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; } } diff --git a/src/lstrlib.c b/src/lstrlib.c index 99ce452a..12264f88 100644 --- a/src/lstrlib.c +++ b/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.250 2016/05/18 18:19:51 roberto Exp $ +** $Id: lstrlib.c,v 1.251 2016/05/20 14:13:21 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -928,20 +928,14 @@ static void addquoted (luaL_Buffer *b, const char *s, size_t len) { /* -** Convert a Lua number to a string in floating-point hexadecimal -** format. Ensures the resulting string uses a dot as the radix -** character. +** Ensures the 'buff' string uses a dot as the radix character. */ -static void addliteralnum (lua_State *L, luaL_Buffer *b, lua_Number n) { - char *buff = luaL_prepbuffsize(b, MAX_ITEM); - int nb = lua_number2strx(L, buff, MAX_ITEM, - "%" LUA_NUMBER_FRMLEN "a", n); +static void checkdp (char *buff, int nb) { if (memchr(buff, '.', nb) == NULL) { /* no dot? */ char point = lua_getlocaledecpoint(); /* try locale point */ char *ppoint = memchr(buff, point, nb); if (ppoint) *ppoint = '.'; /* change it to a dot */ } - luaL_addsize(b, nb); } @@ -954,12 +948,23 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { break; } case LUA_TNUMBER: { - if (!lua_isinteger(L, arg)) { /* write floats as hexa ('%a') */ - addliteralnum(L, b, lua_tonumber(L, arg)); - break; + char *buff = luaL_prepbuffsize(b, MAX_ITEM); + int nb; + if (!lua_isinteger(L, arg)) { /* float? */ + lua_Number n = lua_tonumber(L, arg); /* write as hexa ('%a') */ + nb = lua_number2strx(L, buff, MAX_ITEM, "%" LUA_NUMBER_FRMLEN "a", n); + checkdp(buff, nb); /* ensure it uses a dot */ + } + else { /* integers */ + lua_Integer n = lua_tointeger(L, arg); + const char *format = (n == LUA_MININTEGER) /* corner case? */ + ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */ + : LUA_INTEGER_FMT; /* else use default format */ + nb = l_sprintf(buff, MAX_ITEM, format, n); } - /* else integers; write in "native" format */ - } /* FALLTHROUGH */ + luaL_addsize(b, nb); + break; + } case LUA_TNIL: case LUA_TBOOLEAN: { luaL_tolstring(L, arg, NULL); luaL_addvalue(b); @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.330 2016/01/13 17:55:19 roberto Exp $ +** $Id: lua.h,v 1.331 2016/05/30 15:53:28 roberto Exp $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -361,7 +361,7 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); #define lua_pushliteral(L, s) lua_pushstring(L, "" s) #define lua_pushglobaltable(L) \ - lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS) + ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)) #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) |