diff options
-rw-r--r-- | lstrlib.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.173 2011/11/30 18:24:56 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.174 2012/04/03 19:06:19 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -758,9 +758,6 @@ static int str_gsub (lua_State *L) { | |||
758 | #endif | 758 | #endif |
759 | #endif /* } */ | 759 | #endif /* } */ |
760 | 760 | ||
761 | #define MAX_UINTFRM ((lua_Number)(~(unsigned LUA_INTFRM_T)0)) | ||
762 | #define MAX_INTFRM ((lua_Number)((~(unsigned LUA_INTFRM_T)0)/2)) | ||
763 | #define MIN_INTFRM (-(lua_Number)((~(unsigned LUA_INTFRM_T)0)/2) - 1) | ||
764 | 761 | ||
765 | /* | 762 | /* |
766 | ** LUA_FLTFRMLEN is the length modifier for float conversions in | 763 | ** LUA_FLTFRMLEN is the length modifier for float conversions in |
@@ -872,18 +869,22 @@ static int str_format (lua_State *L) { | |||
872 | } | 869 | } |
873 | case 'd': case 'i': { | 870 | case 'd': case 'i': { |
874 | lua_Number n = luaL_checknumber(L, arg); | 871 | lua_Number n = luaL_checknumber(L, arg); |
875 | luaL_argcheck(L, (MIN_INTFRM - 1) < n && n < (MAX_INTFRM + 1), arg, | 872 | LUA_INTFRM_T ni = (LUA_INTFRM_T)n; |
873 | lua_Number diff = n - (lua_Number)ni; | ||
874 | luaL_argcheck(L, -1 < diff && diff < 1, arg, | ||
876 | "not a number in proper range"); | 875 | "not a number in proper range"); |
877 | addlenmod(form, LUA_INTFRMLEN); | 876 | addlenmod(form, LUA_INTFRMLEN); |
878 | nb = sprintf(buff, form, (LUA_INTFRM_T)n); | 877 | nb = sprintf(buff, form, ni); |
879 | break; | 878 | break; |
880 | } | 879 | } |
881 | case 'o': case 'u': case 'x': case 'X': { | 880 | case 'o': case 'u': case 'x': case 'X': { |
882 | lua_Number n = luaL_checknumber(L, arg); | 881 | lua_Number n = luaL_checknumber(L, arg); |
883 | luaL_argcheck(L, 0 <= n && n < (MAX_UINTFRM + 1), arg, | 882 | unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n; |
883 | lua_Number diff = n - (lua_Number)ni; | ||
884 | luaL_argcheck(L, -1 < diff && diff < 1, arg, | ||
884 | "not a non-negative number in proper range"); | 885 | "not a non-negative number in proper range"); |
885 | addlenmod(form, LUA_INTFRMLEN); | 886 | addlenmod(form, LUA_INTFRMLEN); |
886 | nb = sprintf(buff, form, (unsigned LUA_INTFRM_T)n); | 887 | nb = sprintf(buff, form, ni); |
887 | break; | 888 | break; |
888 | } | 889 | } |
889 | case 'e': case 'E': case 'f': | 890 | case 'e': case 'E': case 'f': |