diff --git a/lstrlib.c b/lstrlib.c index cd10c320..6c8e1ba4 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.141 2008/06/12 14:21:18 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.142 2009/02/03 19:39:19 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -777,14 +777,13 @@ static int str_format (lua_State *L) { sprintf(buff, form, (int)luaL_checknumber(L, arg)); break; } - case 'd': case 'i': { - addintlen(form); - sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); - break; - } + case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': { + lua_Number n = luaL_checknumber(L, arg); + LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n : + (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n; addintlen(form); - sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + sprintf(buff, form, r); break; } case 'e': case 'E': case 'f':