aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-05-18 15:19:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-05-18 15:19:51 -0300
commit4d5ab9baa64f671b3b0c030821c9502302937dc9 (patch)
tree2b3e90e32cef7b1a956ea8687a648926a49267a6 /lstrlib.c
parentb65252b39bbda0a75a56135da4765cc540922389 (diff)
downloadlua-4d5ab9baa64f671b3b0c030821c9502302937dc9.tar.gz
lua-4d5ab9baa64f671b3b0c030821c9502302937dc9.tar.bz2
lua-4d5ab9baa64f671b3b0c030821c9502302937dc9.zip
'string.pack("cn")' does not accept strings longer than 'n'
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 06f688a9..9ba16a55 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -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 */