diff options
| -rw-r--r-- | lstrlib.c | 19 |
1 files changed, 14 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.169 2011/06/16 14:14:05 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.170 2011/06/28 17:13:52 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 | */ |
| @@ -154,7 +154,7 @@ static int str_char (lua_State *L) { | |||
| 154 | char *p = luaL_buffinitsize(L, &b, n); | 154 | char *p = luaL_buffinitsize(L, &b, n); |
| 155 | for (i=1; i<=n; i++) { | 155 | for (i=1; i<=n; i++) { |
| 156 | int c = luaL_checkint(L, i); | 156 | int c = luaL_checkint(L, i); |
| 157 | luaL_argcheck(L, uchar(c) == c, i, "invalid value"); | 157 | luaL_argcheck(L, uchar(c) == c, i, "value out of range"); |
| 158 | p[i - 1] = uchar(c); | 158 | p[i - 1] = uchar(c); |
| 159 | } | 159 | } |
| 160 | luaL_pushresultsize(&b, n); | 160 | luaL_pushresultsize(&b, n); |
| @@ -865,11 +865,20 @@ static int str_format (lua_State *L) { | |||
| 865 | nb = sprintf(buff, form, luaL_checkint(L, arg)); | 865 | nb = sprintf(buff, form, luaL_checkint(L, arg)); |
| 866 | break; | 866 | break; |
| 867 | } | 867 | } |
| 868 | case 'd': case 'i': | 868 | case 'd': case 'i': { |
| 869 | lua_Number n = luaL_checknumber(L, arg); | ||
| 870 | LUA_INTFRM_T r = (LUA_INTFRM_T)n; | ||
| 871 | luaL_argcheck(L, (lua_Number)r == n, arg, | ||
| 872 | "not an integer in proper range"); | ||
| 873 | addlenmod(form, LUA_INTFRMLEN); | ||
| 874 | nb = sprintf(buff, form, r); | ||
| 875 | break; | ||
| 876 | } | ||
| 869 | case 'o': case 'u': case 'x': case 'X': { | 877 | case 'o': case 'u': case 'x': case 'X': { |
| 870 | lua_Number n = luaL_checknumber(L, arg); | 878 | lua_Number n = luaL_checknumber(L, arg); |
| 871 | LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n : | 879 | unsigned LUA_INTFRM_T r = (unsigned LUA_INTFRM_T)n; |
| 872 | (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n; | 880 | luaL_argcheck(L, (lua_Number)r == n, arg, |
| 881 | "not a non-negative integer in proper range"); | ||
| 873 | addlenmod(form, LUA_INTFRMLEN); | 882 | addlenmod(form, LUA_INTFRMLEN); |
| 874 | nb = sprintf(buff, form, r); | 883 | nb = sprintf(buff, form, r); |
| 875 | break; | 884 | break; |
