diff --git a/src/Frame.cc b/src/Frame.cc index 6d60a34401..dd1a9dc598 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -43,6 +43,7 @@ Frame::Frame(int arg_size, const ScriptFunc* func, const zeek::Args* fn_args) void Frame::SetElement(int n, ValPtr v) { n += current_offset; + ASSERT(n >= 0 && n < size); frame[n] = std::move(v); } diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index 2da500681c..ca570ec41a 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -37,7 +37,7 @@ void finalize_functions(const std::vector& funcs) std::unordered_set leave_alone; for ( auto& f : funcs ) - if ( f.Body()->Tag() != STMT_ZAM ) + if ( f.Body() && f.Body()->Tag() != STMT_ZAM ) // This function has a body that wasn't compiled, // don't mess with its size. leave_alone.insert(f.Func()); @@ -473,7 +473,8 @@ void ZAMCompiler::ComputeFrameLifetimes() int n = aux->n; auto& slots = aux->slots; for ( int i = 0; i < n; ++i ) - ExtendLifetime(slots[i], EndOfLoop(inst, 1)); + if ( slots[i] >= 0 ) + ExtendLifetime(slots[i], EndOfLoop(inst, 1)); break; } @@ -839,6 +840,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst) void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst) { + ASSERT(slot >= 0); auto id = frame_denizens[slot]; auto& t = id->GetType();