mirror of
https://github.com/janet-lang/janet
synced 2024-12-23 06:50:26 +00:00
Fix #1174 - bad debug info causing stack traversal to segfault.
Coming from commit 77189b6e66
, relating
to changes in source mapping debug info, this caused a segfault when
traversing a stack frame where the birth_pc was incredibly large due
to wrap around. This fix prevents the wrap around and does saturating
subtraction to 0.
This commit is contained in:
parent
26a113927e
commit
e97299fc65
@ -978,7 +978,14 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) {
|
|||||||
jsm.death_pc = pair.death_pc - scope->bytecode_start;
|
jsm.death_pc = pair.death_pc - scope->bytecode_start;
|
||||||
}
|
}
|
||||||
/* Handle birth_pc == 0 correctly */
|
/* Handle birth_pc == 0 correctly */
|
||||||
jsm.birth_pc = pair.birth_pc ? pair.birth_pc - scope->bytecode_start : 0;
|
if ((uint32_t) scope->bytecode_start > pair.birth_pc) {
|
||||||
|
jsm.birth_pc = 0;
|
||||||
|
} else {
|
||||||
|
jsm.birth_pc = pair.birth_pc - scope->bytecode_start;
|
||||||
|
}
|
||||||
|
janet_assert(jsm.birth_pc <= jsm.death_pc, "birth pc after death pc");
|
||||||
|
janet_assert(jsm.birth_pc < (uint32_t) def->bytecode_length, "bad birth pc");
|
||||||
|
janet_assert(jsm.death_pc <= (uint32_t) def->bytecode_length, "bad death pc");
|
||||||
jsm.slot_index = pair.slot.index;
|
jsm.slot_index = pair.slot.index;
|
||||||
jsm.symbol = pair.sym2;
|
jsm.symbol = pair.sym2;
|
||||||
janet_v_push(locals, jsm);
|
janet_v_push(locals, jsm);
|
||||||
|
@ -47,4 +47,15 @@
|
|||||||
|
|
||||||
(assert (= 10 (do (var x 10) (def y x) (++ x) y)) "no invalid aliasing")
|
(assert (= 10 (do (var x 10) (def y x) (++ x) y)) "no invalid aliasing")
|
||||||
|
|
||||||
|
# Crash issue #1174 - bad debug info
|
||||||
|
(defn crash []
|
||||||
|
(debug/stack (fiber/current)))
|
||||||
|
(do
|
||||||
|
(math/random)
|
||||||
|
(defn foo [_]
|
||||||
|
(crash)
|
||||||
|
1)
|
||||||
|
(foo 0)
|
||||||
|
10)
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user