ASSERT seatbelts for low-level vector accesses

This commit is contained in:
Vern Paxson 2023-07-13 11:42:53 -07:00
parent c61360e181
commit 3505827982
2 changed files with 5 additions and 2 deletions

View file

@ -43,6 +43,7 @@ Frame::Frame(int arg_size, const ScriptFunc* func, const zeek::Args* fn_args)
void Frame::SetElement(int n, ValPtr v) void Frame::SetElement(int n, ValPtr v)
{ {
n += current_offset; n += current_offset;
ASSERT(n >= 0 && n < size);
frame[n] = std::move(v); frame[n] = std::move(v);
} }

View file

@ -37,7 +37,7 @@ void finalize_functions(const std::vector<FuncInfo>& funcs)
std::unordered_set<const Func*> leave_alone; std::unordered_set<const Func*> leave_alone;
for ( auto& f : funcs ) 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, // This function has a body that wasn't compiled,
// don't mess with its size. // don't mess with its size.
leave_alone.insert(f.Func()); leave_alone.insert(f.Func());
@ -473,7 +473,8 @@ void ZAMCompiler::ComputeFrameLifetimes()
int n = aux->n; int n = aux->n;
auto& slots = aux->slots; auto& slots = aux->slots;
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
ExtendLifetime(slots[i], EndOfLoop(inst, 1)); if ( slots[i] >= 0 )
ExtendLifetime(slots[i], EndOfLoop(inst, 1));
break; break;
} }
@ -839,6 +840,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst)
void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst) void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst)
{ {
ASSERT(slot >= 0);
auto id = frame_denizens[slot]; auto id = frame_denizens[slot];
auto& t = id->GetType(); auto& t = id->GetType();