mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
ReplaceBody now deletes a body if the replacement is nil
This commit is contained in:
parent
2ec2e1e7d7
commit
98f549d65d
2 changed files with 27 additions and 11 deletions
24
src/Func.cc
24
src/Func.cc
|
@ -332,8 +332,11 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft,
|
|||
|
||||
sort(bodies.begin(), bodies.end());
|
||||
|
||||
current_body = bodies[0].stmts;
|
||||
current_priority = bodies[0].priority;
|
||||
if ( bodies.size() > 0 )
|
||||
{
|
||||
current_body = bodies[0].stmts;
|
||||
current_priority = bodies[0].priority;
|
||||
}
|
||||
}
|
||||
|
||||
ScriptFunc::~ScriptFunc()
|
||||
|
@ -579,15 +582,22 @@ void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body)
|
|||
{
|
||||
bool found_it = false;
|
||||
|
||||
for ( auto& body : bodies )
|
||||
if ( body.stmts.get() == old_body.get() )
|
||||
for ( auto body = bodies.begin(); body != bodies.end(); ++body )
|
||||
if ( body->stmts.get() == old_body.get() )
|
||||
{
|
||||
body.stmts = new_body;
|
||||
current_priority = body.priority;
|
||||
if ( new_body )
|
||||
{
|
||||
body->stmts = new_body;
|
||||
current_priority = body->priority;
|
||||
}
|
||||
else
|
||||
bodies.erase(body);
|
||||
|
||||
found_it = true;
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(found_it);
|
||||
// ASSERT(found_it);
|
||||
current_body = new_body;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue