diff options
| -rw-r--r-- | lstrlib.c | 14 |
1 files changed, 6 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.248 2016/05/02 13:58:01 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.249 2016/05/13 19:09:46 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 | */ |
| @@ -1369,13 +1369,11 @@ static int str_pack (lua_State *L) { | |||
| 1369 | case Kchar: { /* fixed-size string */ | 1369 | case Kchar: { /* fixed-size string */ |
| 1370 | size_t len; | 1370 | size_t len; |
| 1371 | const char *s = luaL_checklstring(L, arg, &len); | 1371 | const char *s = luaL_checklstring(L, arg, &len); |
| 1372 | if ((size_t)size <= len) /* string larger than (or equal to) needed? */ | 1372 | luaL_argcheck(L, len <= (size_t)size, arg, |
| 1373 | luaL_addlstring(&b, s, size); /* truncate string to asked size */ | 1373 | "string longer than given size"); |
| 1374 | else { /* string smaller than needed */ | 1374 | luaL_addlstring(&b, s, len); /* add string */ |
| 1375 | luaL_addlstring(&b, s, len); /* add it all */ | 1375 | while (len++ < (size_t)size) /* pad extra space */ |
| 1376 | while (len++ < (size_t)size) /* pad extra space */ | 1376 | luaL_addchar(&b, LUAL_PACKPADBYTE); |
| 1377 | luaL_addchar(&b, LUAL_PACKPADBYTE); | ||
| 1378 | } | ||
| 1379 | break; | 1377 | break; |
| 1380 | } | 1378 | } |
| 1381 | case Kstring: { /* strings with length count */ | 1379 | case Kstring: { /* strings with length count */ |
