mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Reporter: Add ExprRuntimeWarning()
...and update Expr.cc invalidation messages to use it. This aligns the warning format to the one used by runtime errors.
This commit is contained in:
parent
0e97c29eb8
commit
a07b0c333f
4 changed files with 26 additions and 28 deletions
27
src/Expr.cc
27
src/Expr.cc
|
@ -274,14 +274,7 @@ void Expr::AssignToIndex(ValPtr v1, ValPtr v2, ValPtr v3) const
|
||||||
iterators_invalidated);
|
iterators_invalidated);
|
||||||
|
|
||||||
if ( iterators_invalidated )
|
if ( iterators_invalidated )
|
||||||
{
|
reporter->ExprRuntimeWarning(this, "possible loop/iterator invalidation");
|
||||||
ODesc d;
|
|
||||||
Describe(&d);
|
|
||||||
reporter->PushLocation(GetLocationInfo());
|
|
||||||
reporter->Warning("possible loop/iterator invalidation caused by expression: %s",
|
|
||||||
d.Description());
|
|
||||||
reporter->PopLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( error_msg )
|
if ( error_msg )
|
||||||
RuntimeErrorWithCallStack(error_msg);
|
RuntimeErrorWithCallStack(error_msg);
|
||||||
|
@ -2974,14 +2967,7 @@ void IndexExpr::Add(Frame* f)
|
||||||
v1->AsTableVal()->Assign(std::move(v2), nullptr, true, &iterators_invalidated);
|
v1->AsTableVal()->Assign(std::move(v2), nullptr, true, &iterators_invalidated);
|
||||||
|
|
||||||
if ( iterators_invalidated )
|
if ( iterators_invalidated )
|
||||||
{
|
reporter->ExprRuntimeWarning(this, "possible loop/iterator invalidation");
|
||||||
ODesc d;
|
|
||||||
Describe(&d);
|
|
||||||
reporter->PushLocation(GetLocationInfo());
|
|
||||||
reporter->Warning("possible loop/iterator invalidation caused by expression: %s",
|
|
||||||
d.Description());
|
|
||||||
reporter->PopLocation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexExpr::Delete(Frame* f)
|
void IndexExpr::Delete(Frame* f)
|
||||||
|
@ -3003,14 +2989,7 @@ void IndexExpr::Delete(Frame* f)
|
||||||
v1->AsTableVal()->Remove(*v2, true, &iterators_invalidated);
|
v1->AsTableVal()->Remove(*v2, true, &iterators_invalidated);
|
||||||
|
|
||||||
if ( iterators_invalidated )
|
if ( iterators_invalidated )
|
||||||
{
|
reporter->ExprRuntimeWarning(this, "possible loop/iterator invalidation");
|
||||||
ODesc d;
|
|
||||||
Describe(&d);
|
|
||||||
reporter->PushLocation(GetLocationInfo());
|
|
||||||
reporter->Warning("possible loop/iterator invalidation caused by expression: %s",
|
|
||||||
d.Description());
|
|
||||||
reporter->PopLocation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprPtr IndexExpr::MakeLvalue()
|
ExprPtr IndexExpr::MakeLvalue()
|
||||||
|
|
|
@ -174,6 +174,21 @@ void Reporter::ExprRuntimeError(const detail::Expr* expr, const char* fmt, ...)
|
||||||
throw InterpreterException();
|
throw InterpreterException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Reporter::ExprRuntimeWarning(const detail::Expr* expr, const char* fmt, ...)
|
||||||
|
{
|
||||||
|
ODesc d;
|
||||||
|
expr->Describe(&d);
|
||||||
|
|
||||||
|
PushLocation(expr->GetLocationInfo());
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
FILE* out = EmitToStderr(warnings_to_stderr) ? stderr : nullptr;
|
||||||
|
DoLog("expression warning", reporter_warning, out, nullptr, nullptr, true, true,
|
||||||
|
d.Description(), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
PopLocation();
|
||||||
|
}
|
||||||
|
|
||||||
void Reporter::RuntimeError(const detail::Location* location, const char* fmt, ...)
|
void Reporter::RuntimeError(const detail::Location* location, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
++errors;
|
++errors;
|
||||||
|
|
|
@ -112,6 +112,10 @@ public:
|
||||||
[[noreturn]] void RuntimeError(const detail::Location* location, const char* fmt, ...)
|
[[noreturn]] void RuntimeError(const detail::Location* location, const char* fmt, ...)
|
||||||
__attribute__((format(printf, 3, 4)));
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
|
// Report a rutnime warning in evaluating a Zeek script expression.
|
||||||
|
void ExprRuntimeWarning(const detail::Expr* expr, const char* fmt, ...)
|
||||||
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
// Report a runtime error in executing a compiled script. This
|
// Report a runtime error in executing a compiled script. This
|
||||||
// function will not return but raise an InterpreterException.
|
// function will not return but raise an InterpreterException.
|
||||||
[[noreturn]] void CPPRuntimeError(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
|
[[noreturn]] void CPPRuntimeError(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
warning in <...>/table-set-iterator-invalidation.zeek, line 22: possible loop/iterator invalidation caused by expression: t[4]
|
expression warning in <...>/table-set-iterator-invalidation.zeek, line 22: possible loop/iterator invalidation (t[4])
|
||||||
warning in <...>/table-set-iterator-invalidation.zeek, line 31: possible loop/iterator invalidation caused by expression: t[4]
|
expression warning in <...>/table-set-iterator-invalidation.zeek, line 31: possible loop/iterator invalidation (t[4])
|
||||||
warning in <...>/table-set-iterator-invalidation.zeek, line 54: possible loop/iterator invalidation caused by expression: s[4]
|
expression warning in <...>/table-set-iterator-invalidation.zeek, line 54: possible loop/iterator invalidation (s[4])
|
||||||
warning in <...>/table-set-iterator-invalidation.zeek, line 63: possible loop/iterator invalidation caused by expression: s[4]
|
expression warning in <...>/table-set-iterator-invalidation.zeek, line 63: possible loop/iterator invalidation (s[4])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue