[PATCH] BUG: Missing 'lua_State' parameter in 'floatforloop'

81 views
Skip to first unread message

Weixie Cui

unread,
Mar 11, 2026, 1:25:45 AM (7 days ago) Mar 11
to lu...@googlegroups.com, Weixie Cui
From: Weixie Cui <cuiw...@gmail.com>

'floatforloop' uses 'L' in 'luai_numadd(L, idx, step)' but does
not receive it as a parameter. It compiles only because the default
'luai_numadd' macro ignores 'L'; custom redefinitions would break.
The sibling function 'forprep' correctly takes 'lua_State *L'.
---
lvm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lvm.c b/lvm.c
index c70e2b8a..612369cb 100644
--- a/lvm.c
+++ b/lvm.c
@@ -270,7 +270,7 @@ static int forprep (lua_State *L, StkId ra) {
** true iff the loop must continue. (The integer case is
** written online with opcode OP_FORLOOP, for performance.)
*/
-static int floatforloop (StkId ra) {
+static int floatforloop (lua_State *L, StkId ra) {
lua_Number step = fltvalue(s2v(ra + 1));
lua_Number limit = fltvalue(s2v(ra));
lua_Number idx = fltvalue(s2v(ra + 2)); /* control variable */
@@ -1841,7 +1841,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
pc -= GETARG_Bx(i); /* jump back */
}
}
- else if (floatforloop(ra)) /* float loop */
+ else if (floatforloop(L, ra)) /* float loop */
pc -= GETARG_Bx(i); /* jump back */
updatetrap(ci); /* allows a signal to break the loop */
vmbreak;
--
2.39.5 (Apple Git-154)

Roberto Ierusalimschy

unread,
Mar 11, 2026, 10:06:53 AM (7 days ago) Mar 11
to 'Weixie Cui' via lua-l
> 'floatforloop' uses 'L' in 'luai_numadd(L, idx, step)' but does
> not receive it as a parameter. It compiles only because the default
> 'luai_numadd' macro ignores 'L'; custom redefinitions would break.

Thanks for the feedback.

-- Roberto
Reply all
Reply to author
Forward
0 new messages