]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: hlua: simplify ambiguous lua_insert() usage in hlua_ctx_resume()
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 4 Jun 2024 13:52:23 +0000 (15:52 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 4 Jun 2024 14:31:38 +0000 (16:31 +0200)
'lua_insert(lua->T, -lua_gettop(lua->T))' is actually used to rotate the
top value with the bottom one, thus the code was overkill and the comment
was actually misleading, let's fix that by using explicit equivalent form
(absolute index).

It may be backported with 5508db9a2 ("BUG/MINOR: hlua: fix unsafe
lua_tostring() usage with empty stack") to all stable versions to ease
code maintenance.

src/hlua.c

index f108c6ed8a048bd5e592de1e0d7cf067d53f6ccb..8434ed73a1011a68a89e8aef0c94e4e854b7b771 100644 (file)
@@ -2087,8 +2087,8 @@ resume_execution:
                        hlua_pushfstring_safe(lua->T, "[state-id %d] unknown runtime error from %s",
                                              lua->state_id, trace);
 
-               /* Move the error msg at the top and then empty the stack except last msg */
-               lua_insert(lua->T, -lua_gettop(lua->T));
+               /* Move the error msg at the bottom and then empty the stack except last msg */
+               lua_insert(lua->T, 1);
                lua_settop(lua->T, 1);
                ret = HLUA_E_ERRMSG;
                break;
@@ -2113,8 +2113,8 @@ resume_execution:
                        hlua_pushfstring_safe(lua->T, "[state-id %d] message handler error",
                                              lua->state_id);
 
-               /* Move the error msg at the top and then empty the stack except last msg */
-               lua_insert(lua->T, -lua_gettop(lua->T));
+               /* Move the error msg at the bottom and then empty the stack except last msg */
+               lua_insert(lua->T, 1);
                lua_settop(lua->T, 1);
                ret = HLUA_E_ERRMSG;
                break;