Summary #
The modules.inc file ends with a NULL sentinel, but the C code loop checks modules[i].name != NULL. The generated data includes a trailing comma on the last entry, which may cause the C initializer to expect one more element.
The Problem #
In nix/package.nix the generated modulesInc ends with a trailing comma: ' { "${m.modname}", (const char *)lua_src_${m.ident}, lua_src_${m.ident}_len },' followed by an empty MODINC line. In C, a trailing comma in an initializer is allowed, but the sentinel { NULL, NULL, 0 } is NOT included. The C code in main.c uses a sentinel loop: for (int i = 0; modules[i].name != NULL; i++). Without the sentinel, the loop will read past the last entry and potentially crash or read garbage. The old bytecode build explicitly had a sentinel. The new source embed may have omitted it.
Impact #
- category: correctness
- description: missing sentinel in generated modules.inc causes C iteration past array bounds and potential crash
Recommended Fix #
Add a sentinel entry at the end of modules.inc (e.g., { NULL, NULL, 0 }). Also ensure the generated modulesInc includes this sentinel. Alternatively, change the C code to use the array size from sizeof(modules)/sizeof(modules[0]) - 1 if the sentinel is not present.
Commit range: b0473de..b0473de
Code Review: CR-2026-07-27-11