Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reported by Mathias Westerdahl. (cherry picked from commit 633f265) Lua 5.1 Reference Manual [1] defines a function `lua_concat`, that: > void lua_concat (lua_State *L, int n); > > Concatenates the n values at the top of the stack, pops them, and leaves > the result at the top. Without the patch `lua_concat()` behaved incorrectly with userdata with defined `__concat` metamethod. The problem is GC64-specific. Assuming we have three literals and a userdata with defined "__concat" metamethod on top of the Lua stack: 1 [string] 2 [string] 3 [string] 4 [string] 5 [userdata] <--- top On attempt to concatenate *two* items on top of the Lua stack, `lua_concat()` concatenates *four* items and leaves result on the top: 1 [string] 2 [string][string][string][userdata] <--- top The problem is in incorrect calculation of `n` counter in the loop in implementation of function `lua_concat`. Without the fix `n` is equal to 3 at the end of the first iteration and therefore it goes to the next iteration of concatenation. In the fixed implementation of `lua_concat()` `n` is equal to 1 at the end of the first loop iteration, decremented in a loop postcondition and breaks the loop. The patch fixes incorrect behaviour. 1. https://www.lua.org/manual/5.1/manual.html Sergey Bronnikov: * added the description and the test for the problem Part of tarantool/tarantool#8825
- Loading branch information