Sitelet https://github.com/lua/lua/commit/ae5b5ba529753c7a653901ffc29b5ea24c3fdf3a
Skip to content

Commit ae5b5ba

Browse files
committed
Fixed bug: line hooks in stripped functions
Line-hook handling was accessing debug info. without checking whether it was present.
1 parent a585eae commit ae5b5ba

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎ldebug.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,13 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
783783
** previous instruction 'oldpc'.
784784
*/
785785
static int changedline (const Proto *p, int oldpc, int newpc) {
786+
if (p->lineinfo == NULL) /* no debug information? */
787+
return 0;
786788
while (oldpc++ < newpc) {
787789
if (p->lineinfo[oldpc] != 0)
788790
return (luaG_getfuncline(p, oldpc - 1) != luaG_getfuncline(p, newpc));
789791
}
790-
return 0; /* no line changes in the way */
792+
return 0; /* no line changes between positions */
791793
}
792794

793795

‎testes/db.lua‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ end
884884

885885

886886
print("testing debug functions on chunk without debug info")
887-
prog = [[-- program to be loaded without debug information
887+
prog = [[-- program to be loaded without debug information (strip)
888888
local debug = require'debug'
889889
local a = 12 -- a local variable
890890
@@ -927,6 +927,23 @@ local f = assert(load(string.dump(load(prog), true)))
927927

928928
assert(f() == 13)
929929

930+
do -- bug in 5.4.0: line hooks in stripped code
931+
local function foo ()
932+
local a = 1
933+
local b = 2
934+
return b
935+
end
936+
937+
local s = load(string.dump(foo, true))
938+
local line = true
939+
debug.sethook(function (e, l)
940+
assert(e == "line")
941+
line = l
942+
end, "l")
943+
assert(s() == 2); debug.sethook(nil)
944+
assert(line == nil) -- hook called withoug debug info for 1st instruction
945+
end
946+
930947
do -- tests for 'source' in binary dumps
931948
local prog = [[
932949
return function (x)

0 commit comments

Comments
 (0)