Stmt: Fix assert evaluating cond twice

Since 81a9745fb3, the assert condition is
evaluated twice. This leads to unexpected behavior when cond has a side
effect like publishing a message or creating a log stream or filter.

Found while using the following in ad-hoc testing code and wondering
why two messages were published.

    assert publish(Cluster::worker_topic, hello, "abc")
This commit is contained in:
Arne Welzel 2024-03-04 14:16:06 +01:00
parent 724daa2792
commit 6572324b8c
4 changed files with 36 additions and 1 deletions

View file

@ -1644,7 +1644,7 @@ ValPtr AssertStmt::Exec(Frame* f, StmtFlowType& flow) {
bool run_result_hook = assertion_result_hook && assertion_result_hook->HasEnabledBodies();
auto assert_result = cond->Eval(f)->AsBool();
if ( ! cond->Eval(f)->AsBool() || run_result_hook ) {
if ( ! assert_result || run_result_hook ) {
zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString();
if ( msg ) {