Skip to content

Commit

Permalink
Fix default end index for table.concat and unpack
Browse files Browse the repository at this point in the history
These were broken in commit 836a38a
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".
  • Loading branch information
Meorawr committed Aug 31, 2022
1 parent 4d29847 commit 837c0d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion liblua/lbaselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand Down
2 changes: 1 addition & 1 deletion liblua/ltablib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 837c0d9

Please sign in to comment.