Weird behavior in the stand-alone interpreter for '--' argument

149 views
Skip to first unread message

Jure Bagić

unread,
Jul 4, 2025, 2:19:20 PMJul 4
to lua-l

When executing Lua standalone interpreter from command line like this:
> lua "-e " --
this outputs memory error "not enough memory" (v5.4.8), or in the current mirror
on the github the error is "table overflow".

This is because after '--' option is parsed, the integer pointer 'first' is
set to the 'i + 1', which is 3 in the case above.
However this is one too many, as later in 'createargtable', 'narg' becomes
negative, so the cast to unsigned integer in 'lua_createtable' tries to allocate
huge array part for the table, which raises the mentioned error(s).

Would the desired behavior be to act the same as if the command line was this:
> lua "-e "
This does not invoke error and just runs the empty string, I would expect
the same for the first example. Maybe checking for presence of script argument
after '--' before setting 'first' and returning 'args' would be the easy fix.
For example, if there is no script name after '--', set 'first' to 0.

-- Jure
signature.asc

Roberto Ierusalimschy

unread,
Jul 8, 2025, 1:25:42 PMJul 8
to lu...@googlegroups.com
Indeed, this is a bug. Many thanks for the feedback.

-- Roberto

Andrey Dobrovolsky

unread,
Jul 8, 2025, 2:21:24 PMJul 8
to lu...@googlegroups.com
I'm sorry but I can not reproduce the reported malfunction not for
v5.4.8 nor for v5.5.0. Both standalone interpreters report
$ ./lua "-e" --
./lua: '-e' needs argument
usage: ./lua [options] [script [args]]
Available options are:
-e stat execute string 'stat'
-i enter interactive mode after executing 'script'
-l mod require library 'mod' into global 'mod'
-l g=mod require library 'mod' into global 'g'
-v show version information
-E ignore environment variables
-W turn warnings on
-- stop handling options
- stop handling options and execute stdin

I use Void Linux, what am I doing wrong?

Regards,
-- Andrew

вт, 8 лип. 2025 р. о 20:25 Roberto Ierusalimschy <rob...@inf.puc-rio.br> пише:
> --
> You received this message because you are subscribed to the Google Groups "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/lua-l/20250708172533.GA61852%40arraial.inf.puc-rio.br.

Roberto Ierusalimschy

unread,
Jul 8, 2025, 4:04:54 PMJul 8
to lu...@googlegroups.com
> I'm sorry but I can not reproduce the reported malfunction not for
> v5.4.8 nor for v5.5.0. Both standalone interpreters report
> $ ./lua "-e" --
> ./lua: '-e' needs argument
> usage: ./lua [options] [script [args]]
> Available options are:
> -e stat execute string 'stat'
> -i enter interactive mode after executing 'script'
> -l mod require library 'mod' into global 'mod'
> -l g=mod require library 'mod' into global 'g'
> -v show version information
> -E ignore environment variables
> -W turn warnings on
> -- stop handling options
> - stop handling options and execute stdin
>
> I use Void Linux, what am I doing wrong?

You need "-e " (with a space), not "-e". But you get the bug also
without any -e:

$ lua --
lua: not enough memory

-- Roberto

Andrey Dobrovolsky

unread,
Jul 8, 2025, 5:49:36 PMJul 8
to lu...@googlegroups.com
Thanks a lot! Sorry for my inattention ((

-- Andrew

вт, 8 лип. 2025 р. о 23:04 Roberto Ierusalimschy <rob...@inf.puc-rio.br> пише:
> --
> You received this message because you are subscribed to the Google Groups "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/lua-l/20250708200447.GC84159%40arraial.inf.puc-rio.br.

Roberto Ierusalimschy

unread,
Jul 9, 2025, 10:55:26 AMJul 9
to lu...@googlegroups.com
> Thanks a lot! Sorry for my inattention ((

No problem. The space in "-e " represents the code to be executed. It is
equivalent to 'lua -e " "'.

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