From 837c0d97178f2a4734bac74a991cc90443818878 Mon Sep 17 00:00:00 2001 From: Daniel Yates Date: Wed, 31 Aug 2022 20:48:35 +0100 Subject: [PATCH] Fix default end index for table.concat and unpack These were broken in commit 836a38aaef7dedcf46389b0f94267507e5469f8f which removed deprecated APIs and - accidentally - replaced the index from which the length of the table is calculated to use the `i` parameter as a stack index, instead of a literal "1". --- CHANGELOG.md | 3 ++- liblua/lbaselib.c | 2 +- liblua/ltablib.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b484ed7..7cc555d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## [Unreleased] +## [v2.1] ### Changed - The `lua_Clock` typedef is now an `int64_t` to work around issues on 32-bit platforms. +- Fixed a bug with `table.concat` and `unpack` using an incorrect default value for the optional `j` parameter. ## [v2.0] ### Added diff --git a/liblua/lbaselib.c b/liblua/lbaselib.c index e6b6405..68eacdc 100644 --- a/liblua/lbaselib.c +++ b/liblua/lbaselib.c @@ -328,7 +328,7 @@ static int luaB_unpack (lua_State *L) { int n; luaL_checktype(L, 1, LUA_TTABLE); i = luaL_optint(L, 2, 1); - e = luaL_opt(L, luaL_checkint, 3, (int) lua_objlen(L, i)); + e = luaL_opt(L, luaL_checkint, 3, (int) lua_objlen(L, 1)); if (i > e) { return 0; /* empty range */ } diff --git a/liblua/ltablib.c b/liblua/ltablib.c index 33fd03b..3160fb1 100644 --- a/liblua/ltablib.c +++ b/liblua/ltablib.c @@ -134,7 +134,7 @@ static int table_concat (lua_State *L) { const char *sep = luaL_optlstring(L, 2, "", &lsep); luaL_checktype(L, 1, LUA_TTABLE); i = luaL_optint(L, 3, 1); - last = luaL_opt(L, luaL_checkint, 4, (int) lua_objlen(L, i)); + last = luaL_opt(L, luaL_checkint, 4, (int) lua_objlen(L, 1)); luaL_buffinit(L, &b); for (; i < last; i++) { addfield(L, &b, i);