mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Merge remote-tracking branch 'origin/topic/timw/cleanup'
* origin/topic/timw/cleanup: Expr: use fmt instead of sprintf Expr: other minor initialization cleanup Expr: use List::empty() Expr: Convert a bunch of methods returning ints to return bools IPAddr: minor cleanup PriorityQueue: initialization cleanup IP: Cleanup initialization, make a few functions consistent with others
This commit is contained in:
commit
646a2313ae
10 changed files with 167 additions and 165 deletions
20
CHANGES
20
CHANGES
|
@ -1,4 +1,24 @@
|
|||
|
||||
3.2.0-dev.167 | 2020-02-27 14:24:55 -0800
|
||||
|
||||
* Expr: use fmt instead of sprintf (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* Expr: other minor initialization cleanup (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* Expr: use List::empty() (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* Expr: Convert a bunch of methods returning ints to return bools (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* IPAddr: minor cleanup (Tim Wojtulewicz, Corelight)
|
||||
|
||||
- Mark empty constructors/destructors as default
|
||||
- Initialization cleanup
|
||||
- Remove unnecessary elses from before returns
|
||||
|
||||
* PriorityQueue: initialization cleanup (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* IP: Cleanup initialization, make a few functions consistent (Tim Wojtulewicz, Corelight)
|
||||
|
||||
3.2.0-dev.159 | 2020-02-26 19:51:24 -0800
|
||||
|
||||
* Pop global frame stack on exception. (Johanna Amann, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
3.2.0-dev.159
|
||||
3.2.0-dev.167
|
||||
|
|
123
src/Expr.cc
123
src/Expr.cc
|
@ -55,12 +55,8 @@ const char* expr_name(BroExprTag t)
|
|||
return expr_names[int(t)];
|
||||
}
|
||||
|
||||
Expr::Expr(BroExprTag arg_tag)
|
||||
Expr::Expr(BroExprTag arg_tag) : tag(arg_tag), type(0), paren(false)
|
||||
{
|
||||
tag = arg_tag;
|
||||
type = 0;
|
||||
paren = 0;
|
||||
|
||||
SetLocationInfo(&start_location, &end_location);
|
||||
}
|
||||
|
||||
|
@ -69,14 +65,14 @@ Expr::~Expr()
|
|||
Unref(type);
|
||||
}
|
||||
|
||||
int Expr::CanAdd() const
|
||||
bool Expr::CanAdd() const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int Expr::CanDel() const
|
||||
bool Expr::CanDel() const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Expr::Add(Frame* /* f */)
|
||||
|
@ -113,14 +109,14 @@ BroType* Expr::InitType() const
|
|||
return type->Ref();
|
||||
}
|
||||
|
||||
int Expr::IsRecordElement(TypeDecl* /* td */) const
|
||||
bool Expr::IsRecordElement(TypeDecl* /* td */) const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int Expr::IsPure() const
|
||||
bool Expr::IsPure() const
|
||||
{
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* Expr::InitVal(const BroType* t, Val* aggr) const
|
||||
|
@ -137,7 +133,7 @@ Val* Expr::InitVal(const BroType* t, Val* aggr) const
|
|||
return check_and_promote(Eval(0), t, 1);
|
||||
}
|
||||
|
||||
int Expr::IsError() const
|
||||
bool Expr::IsError() const
|
||||
{
|
||||
return type && type->Tag() == TYPE_ERROR;
|
||||
}
|
||||
|
@ -153,12 +149,12 @@ void Expr::SetError(const char* msg)
|
|||
SetError();
|
||||
}
|
||||
|
||||
int Expr::IsZero() const
|
||||
bool Expr::IsZero() const
|
||||
{
|
||||
return IsConst() && ExprVal()->IsZero();
|
||||
}
|
||||
|
||||
int Expr::IsOne() const
|
||||
bool Expr::IsOne() const
|
||||
{
|
||||
return IsConst() && ExprVal()->IsOne();
|
||||
}
|
||||
|
@ -295,7 +291,7 @@ void NameExpr::Assign(Frame* f, Val* v)
|
|||
f->SetElement(id, v);
|
||||
}
|
||||
|
||||
int NameExpr::IsPure() const
|
||||
bool NameExpr::IsPure() const
|
||||
{
|
||||
return id->IsConst();
|
||||
}
|
||||
|
@ -414,7 +410,7 @@ Val* UnaryExpr::Eval(Frame* f) const
|
|||
}
|
||||
}
|
||||
|
||||
int UnaryExpr::IsPure() const
|
||||
bool UnaryExpr::IsPure() const
|
||||
{
|
||||
return op->IsPure();
|
||||
}
|
||||
|
@ -551,7 +547,7 @@ Val* BinaryExpr::Eval(Frame* f) const
|
|||
return result;
|
||||
}
|
||||
|
||||
int BinaryExpr::IsPure() const
|
||||
bool BinaryExpr::IsPure() const
|
||||
{
|
||||
return op1->IsPure() && op2->IsPure();
|
||||
}
|
||||
|
@ -604,20 +600,20 @@ Val* BinaryExpr::Fold(Val* v1, Val* v2) const
|
|||
bro_int_t i1 = 0, i2 = 0, i3 = 0;
|
||||
bro_uint_t u1 = 0, u2 = 0, u3 = 0;
|
||||
double d1 = 0.0, d2 = 0.0, d3 = 0.0;
|
||||
int is_integral = 0;
|
||||
int is_unsigned = 0;
|
||||
bool is_integral = false;
|
||||
bool is_unsigned = false;
|
||||
|
||||
if ( it == TYPE_INTERNAL_INT )
|
||||
{
|
||||
i1 = v1->InternalInt();
|
||||
i2 = v2->InternalInt();
|
||||
++is_integral;
|
||||
is_integral = true;
|
||||
}
|
||||
else if ( it == TYPE_INTERNAL_UNSIGNED )
|
||||
{
|
||||
u1 = v1->InternalUnsigned();
|
||||
u2 = v2->InternalUnsigned();
|
||||
++is_unsigned;
|
||||
is_unsigned = true;
|
||||
}
|
||||
else if ( it == TYPE_INTERNAL_DOUBLE )
|
||||
{
|
||||
|
@ -858,7 +854,7 @@ Val* BinaryExpr::AddrFold(Val* v1, Val* v2) const
|
|||
{
|
||||
IPAddr a1 = v1->AsAddr();
|
||||
IPAddr a2 = v2->AsAddr();
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
switch ( tag ) {
|
||||
|
||||
|
@ -893,7 +889,7 @@ Val* BinaryExpr::SubNetFold(Val* v1, Val* v2) const
|
|||
const IPPrefix& n1 = v1->AsSubNet();
|
||||
const IPPrefix& n2 = v2->AsSubNet();
|
||||
|
||||
bool result = ( n1 == n2 ) ? true : false;
|
||||
bool result = n1 == n2;
|
||||
|
||||
if ( tag == EXPR_NE )
|
||||
result = ! result;
|
||||
|
@ -1053,9 +1049,9 @@ Val* IncrExpr::Eval(Frame* f) const
|
|||
}
|
||||
}
|
||||
|
||||
int IncrExpr::IsPure() const
|
||||
bool IncrExpr::IsPure() const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
ComplementExpr::ComplementExpr(Expr* arg_op) : UnaryExpr(EXPR_COMPLEMENT, arg_op)
|
||||
|
@ -1605,8 +1601,8 @@ Val* BoolExpr::Eval(Frame* f) const
|
|||
if ( ! v1 )
|
||||
return 0;
|
||||
|
||||
int is_vec1 = is_vector(op1);
|
||||
int is_vec2 = is_vector(op2);
|
||||
bool is_vec1 = is_vector(op1);
|
||||
bool is_vec2 = is_vector(op2);
|
||||
|
||||
// Handle scalar op scalar
|
||||
if ( ! is_vec1 && ! is_vec2 )
|
||||
|
@ -2044,7 +2040,7 @@ Val* CondExpr::Eval(Frame* f) const
|
|||
return result;
|
||||
}
|
||||
|
||||
int CondExpr::IsPure() const
|
||||
bool CondExpr::IsPure() const
|
||||
{
|
||||
return op1->IsPure() && op2->IsPure() && op3->IsPure();
|
||||
}
|
||||
|
@ -2172,7 +2168,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs)
|
|||
std::copy(attrs->begin(), attrs->end(), std::back_inserter(*attr_copy));
|
||||
}
|
||||
|
||||
bool empty_list_assignment = (op2->AsListExpr()->Exprs().length() == 0);
|
||||
bool empty_list_assignment = (op2->AsListExpr()->Exprs().empty());
|
||||
|
||||
if ( op1->Type()->IsSet() )
|
||||
op2 = new SetConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
|
@ -2289,11 +2285,8 @@ bool AssignExpr::TypeCheckArithmetics(TypeTag bt1, TypeTag bt2)
|
|||
{
|
||||
if ( ! IsArithmetic(bt2) )
|
||||
{
|
||||
char err[512];
|
||||
snprintf(err, sizeof(err),
|
||||
"assignment of non-arithmetic value to arithmetic (%s/%s)",
|
||||
type_name(bt1), type_name(bt2));
|
||||
ExprError(err);
|
||||
ExprError(fmt("assignment of non-arithmetic value to arithmetic (%s/%s)",
|
||||
type_name(bt1), type_name(bt2)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2499,7 +2492,7 @@ Val* AssignExpr::InitVal(const BroType* t, Val* aggr) const
|
|||
}
|
||||
}
|
||||
|
||||
int AssignExpr::IsRecordElement(TypeDecl* td) const
|
||||
bool AssignExpr::IsRecordElement(TypeDecl* td) const
|
||||
{
|
||||
if ( op1->Tag() == EXPR_NAME )
|
||||
{
|
||||
|
@ -2510,15 +2503,15 @@ int AssignExpr::IsRecordElement(TypeDecl* td) const
|
|||
td->id = copy_string(n->Id()->Name());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int AssignExpr::IsPure() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssignExpr::IsPure() const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
IndexSliceAssignExpr::IndexSliceAssignExpr(Expr* op1, Expr* op2, int is_init)
|
||||
|
@ -2595,19 +2588,19 @@ IndexExpr::IndexExpr(Expr* arg_op1, ListExpr* arg_op2, bool arg_is_slice)
|
|||
|
||||
}
|
||||
|
||||
int IndexExpr::CanAdd() const
|
||||
bool IndexExpr::CanAdd() const
|
||||
{
|
||||
if ( IsError() )
|
||||
return 1; // avoid cascading the error report
|
||||
return true; // avoid cascading the error report
|
||||
|
||||
// "add" only allowed if our type is "set".
|
||||
return op1->Type()->IsSet();
|
||||
}
|
||||
|
||||
int IndexExpr::CanDel() const
|
||||
bool IndexExpr::CanDel() const
|
||||
{
|
||||
if ( IsError() )
|
||||
return 1; // avoid cascading the error report
|
||||
return true; // avoid cascading the error report
|
||||
|
||||
return op1->Type()->Tag() == TYPE_TABLE;
|
||||
}
|
||||
|
@ -2993,7 +2986,7 @@ Expr* FieldExpr::MakeLvalue()
|
|||
return new RefExpr(this);
|
||||
}
|
||||
|
||||
int FieldExpr::CanDel() const
|
||||
bool FieldExpr::CanDel() const
|
||||
{
|
||||
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
|
||||
}
|
||||
|
@ -3212,7 +3205,7 @@ TableConstructorExpr::TableConstructorExpr(ListExpr* constructor_list,
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( constructor_list->Exprs().length() == 0 )
|
||||
if ( constructor_list->Exprs().empty() )
|
||||
SetType(new TableType(new TypeList(base_type(TYPE_ANY)), 0));
|
||||
else
|
||||
{
|
||||
|
@ -3324,7 +3317,7 @@ SetConstructorExpr::SetConstructorExpr(ListExpr* constructor_list,
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( constructor_list->Exprs().length() == 0 )
|
||||
if ( constructor_list->Exprs().empty() )
|
||||
SetType(new ::SetType(new TypeList(base_type(TYPE_ANY)), 0));
|
||||
else
|
||||
SetType(init_type(constructor_list));
|
||||
|
@ -3441,7 +3434,7 @@ VectorConstructorExpr::VectorConstructorExpr(ListExpr* constructor_list,
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( constructor_list->Exprs().length() == 0 )
|
||||
if ( constructor_list->Exprs().empty() )
|
||||
{
|
||||
// vector().
|
||||
// By default, assign VOID type here. A vector with
|
||||
|
@ -3553,7 +3546,7 @@ void FieldAssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f)
|
|||
}
|
||||
}
|
||||
|
||||
int FieldAssignExpr::IsRecordElement(TypeDecl* td) const
|
||||
bool FieldAssignExpr::IsRecordElement(TypeDecl* td) const
|
||||
{
|
||||
if ( td )
|
||||
{
|
||||
|
@ -3561,7 +3554,7 @@ int FieldAssignExpr::IsRecordElement(TypeDecl* td) const
|
|||
td->id = copy_string(field_name.c_str());
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FieldAssignExpr::ExprDescribe(ODesc* d) const
|
||||
|
@ -4028,9 +4021,9 @@ ScheduleExpr::~ScheduleExpr()
|
|||
Unref(event);
|
||||
}
|
||||
|
||||
int ScheduleExpr::IsPure() const
|
||||
bool ScheduleExpr::IsPure() const
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
Val* ScheduleExpr::Eval(Frame* f) const
|
||||
|
@ -4304,7 +4297,7 @@ CallExpr::~CallExpr()
|
|||
Unref(args);
|
||||
}
|
||||
|
||||
int CallExpr::IsPure() const
|
||||
bool CallExpr::IsPure() const
|
||||
{
|
||||
if ( IsError() )
|
||||
return 1;
|
||||
|
@ -4614,22 +4607,22 @@ void ListExpr::Append(Expr* e)
|
|||
((TypeList*) type)->Append(e->Type()->Ref());
|
||||
}
|
||||
|
||||
int ListExpr::IsPure() const
|
||||
bool ListExpr::IsPure() const
|
||||
{
|
||||
for ( const auto& expr : exprs )
|
||||
if ( ! expr->IsPure() )
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ListExpr::AllConst() const
|
||||
bool ListExpr::AllConst() const
|
||||
{
|
||||
for ( const auto& expr : exprs )
|
||||
if ( ! expr->IsConst() )
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* ListExpr::Eval(Frame* f) const
|
||||
|
@ -4654,7 +4647,7 @@ Val* ListExpr::Eval(Frame* f) const
|
|||
|
||||
BroType* ListExpr::InitType() const
|
||||
{
|
||||
if ( exprs.length() == 0 )
|
||||
if ( exprs.empty() )
|
||||
{
|
||||
Error("empty list in untyped initialization");
|
||||
return 0;
|
||||
|
@ -5321,7 +5314,7 @@ val_list* eval_list(Frame* f, const ListExpr* l)
|
|||
return v;
|
||||
}
|
||||
|
||||
int expr_greater(const Expr* e1, const Expr* e2)
|
||||
bool expr_greater(const Expr* e1, const Expr* e2)
|
||||
{
|
||||
return int(e1->Tag()) > int(e2->Tag());
|
||||
return e1->Tag() > e2->Tag();
|
||||
}
|
||||
|
|
62
src/Expr.h
62
src/Expr.h
|
@ -16,7 +16,7 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
typedef enum {
|
||||
enum BroExprTag : int {
|
||||
EXPR_ANY = -1,
|
||||
EXPR_NAME, EXPR_CONST,
|
||||
EXPR_CLONE,
|
||||
|
@ -54,7 +54,7 @@ typedef enum {
|
|||
EXPR_IS,
|
||||
EXPR_INDEX_SLICE_ASSIGN,
|
||||
#define NUM_EXPRS (int(EXPR_INDEX_SLICE_ASSIGN) + 1)
|
||||
} BroExprTag;
|
||||
};
|
||||
|
||||
extern const char* expr_name(BroExprTag t);
|
||||
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
// constitutes a record element, false otherwise. If the TypeDecl*
|
||||
// is non-nil and the expression is a record element, fills in the
|
||||
// TypeDecl with a description of the element.
|
||||
virtual int IsRecordElement(TypeDecl* td) const;
|
||||
virtual bool IsRecordElement(TypeDecl* td) const;
|
||||
|
||||
// Returns a value corresponding to this expression interpreted
|
||||
// as an initialization, or nil if the expression is inconsistent
|
||||
|
@ -112,13 +112,13 @@ public:
|
|||
virtual Val* InitVal(const BroType* t, Val* aggr) const;
|
||||
|
||||
// True if the expression has no side effects, false otherwise.
|
||||
virtual int IsPure() const;
|
||||
virtual bool IsPure() const;
|
||||
|
||||
// True if the expression is a constant, false otherwise.
|
||||
int IsConst() const { return tag == EXPR_CONST; }
|
||||
bool IsConst() const { return tag == EXPR_CONST; }
|
||||
|
||||
// True if the expression is in error (to alleviate error propagation).
|
||||
int IsError() const;
|
||||
bool IsError() const;
|
||||
|
||||
// Mark expression as in error.
|
||||
void SetError();
|
||||
|
@ -129,15 +129,15 @@ public:
|
|||
inline Val* ExprVal() const;
|
||||
|
||||
// True if the expression is a constant zero, false otherwise.
|
||||
int IsZero() const;
|
||||
bool IsZero() const;
|
||||
|
||||
// True if the expression is a constant one, false otherwise.
|
||||
int IsOne() const;
|
||||
bool IsOne() const;
|
||||
|
||||
// True if the expression supports the "add" or "delete" operations,
|
||||
// false otherwise.
|
||||
virtual int CanAdd() const;
|
||||
virtual int CanDel() const;
|
||||
virtual bool CanAdd() const;
|
||||
virtual bool CanDel() const;
|
||||
|
||||
virtual void Add(Frame* f); // perform add operation
|
||||
virtual void Delete(Frame* f); // perform delete operation
|
||||
|
@ -149,8 +149,8 @@ public:
|
|||
|
||||
// Marks the expression as one requiring (or at least appearing
|
||||
// with) parentheses. Used for pretty-printing.
|
||||
void MarkParen() { paren = 1; }
|
||||
int IsParen() const { return paren; }
|
||||
void MarkParen() { paren = true; }
|
||||
bool IsParen() const { return paren; }
|
||||
|
||||
const ListExpr* AsListExpr() const
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ public:
|
|||
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
|
||||
|
||||
protected:
|
||||
Expr() { type = 0; }
|
||||
Expr() = default;
|
||||
explicit Expr(BroExprTag arg_tag);
|
||||
|
||||
virtual void ExprDescribe(ODesc* d) const = 0;
|
||||
|
@ -225,9 +225,9 @@ protected:
|
|||
void RuntimeErrorWithCallStack(const std::string& msg) const;
|
||||
|
||||
BroExprTag tag;
|
||||
BroType* type;
|
||||
BroType* type = nullptr;
|
||||
|
||||
int paren;
|
||||
bool paren;
|
||||
};
|
||||
|
||||
class NameExpr : public Expr {
|
||||
|
@ -240,7 +240,7 @@ public:
|
|||
Val* Eval(Frame* f) const override;
|
||||
void Assign(Frame* f, Val* v) override;
|
||||
Expr* MakeLvalue() override;
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
|
@ -276,7 +276,7 @@ public:
|
|||
// vectors correctly as necessary.
|
||||
Val* Eval(Frame* f) const override;
|
||||
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
|
@ -297,7 +297,7 @@ public:
|
|||
Expr* Op1() const { return op1; }
|
||||
Expr* Op2() const { return op2; }
|
||||
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
// BinaryExpr::Eval correctly handles vector types. Any child
|
||||
// class that overrides Eval() should be modified to handle
|
||||
|
@ -366,7 +366,7 @@ public:
|
|||
|
||||
Val* Eval(Frame* f) const override;
|
||||
Val* DoSingleEval(Frame* f, Val* v) const;
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
};
|
||||
|
||||
class ComplementExpr : public UnaryExpr {
|
||||
|
@ -490,7 +490,7 @@ public:
|
|||
const Expr* Op3() const { return op3; }
|
||||
|
||||
Val* Eval(Frame* f) const override;
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
|
@ -520,9 +520,9 @@ public:
|
|||
Val* Eval(Frame* f) const override;
|
||||
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
|
||||
BroType* InitType() const override;
|
||||
int IsRecordElement(TypeDecl* td) const override;
|
||||
bool IsRecordElement(TypeDecl* td) const override;
|
||||
Val* InitVal(const BroType* t, Val* aggr) const override;
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
protected:
|
||||
bool TypeCheck(attr_list* attrs = 0);
|
||||
|
@ -542,8 +542,8 @@ class IndexExpr : public BinaryExpr {
|
|||
public:
|
||||
IndexExpr(Expr* op1, ListExpr* op2, bool is_slice = false);
|
||||
|
||||
int CanAdd() const override;
|
||||
int CanDel() const override;
|
||||
bool CanAdd() const override;
|
||||
bool CanDel() const override;
|
||||
|
||||
void Add(Frame* f) override;
|
||||
void Delete(Frame* f) override;
|
||||
|
@ -575,7 +575,7 @@ public:
|
|||
int Field() const { return field; }
|
||||
const char* FieldName() const { return field_name; }
|
||||
|
||||
int CanDel() const override;
|
||||
bool CanDel() const override;
|
||||
|
||||
void Assign(Frame* f, Val* v) override;
|
||||
void Delete(Frame* f) override;
|
||||
|
@ -677,7 +677,7 @@ public:
|
|||
const char* FieldName() const { return field_name.c_str(); }
|
||||
|
||||
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
|
||||
int IsRecordElement(TypeDecl* td) const override;
|
||||
bool IsRecordElement(TypeDecl* td) const override;
|
||||
|
||||
protected:
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
@ -758,7 +758,7 @@ public:
|
|||
ScheduleExpr(Expr* when, EventExpr* event);
|
||||
~ScheduleExpr() override;
|
||||
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
Val* Eval(Frame* f) const override;
|
||||
|
||||
|
@ -791,7 +791,7 @@ public:
|
|||
Expr* Func() const { return func; }
|
||||
ListExpr* Args() const { return args; }
|
||||
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
Val* Eval(Frame* f) const override;
|
||||
|
||||
|
@ -861,10 +861,10 @@ public:
|
|||
expr_list& Exprs() { return exprs; }
|
||||
|
||||
// True if the entire list represents pure values.
|
||||
int IsPure() const override;
|
||||
bool IsPure() const override;
|
||||
|
||||
// True if the entire list represents constant values.
|
||||
int AllConst() const;
|
||||
bool AllConst() const;
|
||||
|
||||
Val* Eval(Frame* f) const override;
|
||||
|
||||
|
@ -943,7 +943,7 @@ val_list* eval_list(Frame* f, const ListExpr* l);
|
|||
// Returns true if e1 is "greater" than e2 - here "greater" is just
|
||||
// a heuristic, used with commutative operators to put them into
|
||||
// a canonical form.
|
||||
extern int expr_greater(const Expr* e1, const Expr* e2);
|
||||
extern bool expr_greater(const Expr* e1, const Expr* e2);
|
||||
|
||||
// True if the given Val* has a vector type
|
||||
inline bool is_vector(Expr* e) { return e->Type()->Tag() == TYPE_VECTOR; }
|
||||
|
|
|
@ -766,7 +766,7 @@ IPv6_Hdr_Chain* IPv6_Hdr_Chain::Copy(const ip6_hdr* new_hdr) const
|
|||
{
|
||||
reporter->InternalWarning("empty IPv6 header chain");
|
||||
delete rval;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const u_char* new_data = (const u_char*)new_hdr;
|
||||
|
|
55
src/IP.h
55
src/IP.h
|
@ -148,11 +148,7 @@ public:
|
|||
/**
|
||||
* Initializes the header chain from an IPv6 header structure.
|
||||
*/
|
||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len) :
|
||||
#ifdef ENABLE_MOBILE_IPV6
|
||||
homeAddr(0),
|
||||
#endif
|
||||
finalDst(0)
|
||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len)
|
||||
{ Init(ip6, len, false); }
|
||||
|
||||
~IPv6_Hdr_Chain();
|
||||
|
@ -236,23 +232,13 @@ protected:
|
|||
// point to a fragment
|
||||
friend class FragReassembler;
|
||||
|
||||
IPv6_Hdr_Chain() :
|
||||
length(0),
|
||||
#ifdef ENABLE_MOBILE_IPV6
|
||||
homeAddr(0),
|
||||
#endif
|
||||
finalDst(0)
|
||||
{}
|
||||
IPv6_Hdr_Chain() = default;
|
||||
|
||||
/**
|
||||
* Initializes the header chain from an IPv6 header structure, and replaces
|
||||
* the first next protocol pointer field that points to a fragment header.
|
||||
*/
|
||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, uint16_t next, int len) :
|
||||
#ifdef ENABLE_MOBILE_IPV6
|
||||
homeAddr(0),
|
||||
#endif
|
||||
finalDst(0)
|
||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, uint16_t next, int len)
|
||||
{ Init(ip6, len, true, next); }
|
||||
|
||||
/**
|
||||
|
@ -282,20 +268,20 @@ protected:
|
|||
/**
|
||||
* The summation of all header lengths in the chain in bytes.
|
||||
*/
|
||||
uint16_t length;
|
||||
uint16_t length = 0;
|
||||
|
||||
#ifdef ENABLE_MOBILE_IPV6
|
||||
/**
|
||||
* Home Address of the packet's source as defined by Mobile IPv6 (RFC 6275).
|
||||
*/
|
||||
IPAddr* homeAddr;
|
||||
IPAddr* homeAddr = nullptr;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The final destination address in chain's first Routing header that has
|
||||
* non-zero segments left.
|
||||
*/
|
||||
IPAddr* finalDst;
|
||||
IPAddr* finalDst = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -311,7 +297,7 @@ public:
|
|||
* @param arg_del whether to take ownership of \a arg_ip4 pointer's memory.
|
||||
*/
|
||||
IP_Hdr(const struct ip* arg_ip4, bool arg_del)
|
||||
: ip4(arg_ip4), ip6(0), del(arg_del), ip6_hdrs(0)
|
||||
: ip4(arg_ip4), del(arg_del)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -327,9 +313,9 @@ public:
|
|||
* @param c an already-constructed header chain to take ownership of.
|
||||
*/
|
||||
IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del, int len,
|
||||
const IPv6_Hdr_Chain* c = 0)
|
||||
: ip4(0), ip6(arg_ip6), del(arg_del),
|
||||
ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len))
|
||||
const IPv6_Hdr_Chain* c = nullptr)
|
||||
: ip6(arg_ip6), ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len)),
|
||||
del(arg_del)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -397,7 +383,7 @@ public:
|
|||
{
|
||||
if ( ip4 )
|
||||
return ((const u_char*) ip4) + ip4->ip_hl * 4;
|
||||
else
|
||||
|
||||
return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
|
||||
}
|
||||
|
||||
|
@ -409,9 +395,9 @@ public:
|
|||
const ip6_mobility* MobilityHeader() const
|
||||
{
|
||||
if ( ip4 )
|
||||
return 0;
|
||||
return nullptr;
|
||||
else if ( (*ip6_hdrs)[ip6_hdrs->Size()-1]->Type() != IPPROTO_MOBILITY )
|
||||
return 0;
|
||||
return nullptr;
|
||||
else
|
||||
return (const ip6_mobility*)(*ip6_hdrs)[ip6_hdrs->Size()-1]->Data();
|
||||
}
|
||||
|
@ -425,7 +411,7 @@ public:
|
|||
{
|
||||
if ( ip4 )
|
||||
return ntohs(ip4->ip_len) - ip4->ip_hl * 4;
|
||||
else
|
||||
|
||||
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength();
|
||||
}
|
||||
|
||||
|
@ -433,7 +419,12 @@ public:
|
|||
* Returns the length of the IP packet (length of headers and payload).
|
||||
*/
|
||||
uint32_t TotalLen() const
|
||||
{ return ip4 ? ntohs(ip4->ip_len) : ntohs(ip6->ip6_plen) + 40; }
|
||||
{
|
||||
if ( ip4 )
|
||||
return ntohs(ip4->ip_len);
|
||||
|
||||
return ntohs(ip6->ip6_plen) + 40;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns length of IP packet header (includes extension headers for IPv6).
|
||||
|
@ -543,8 +534,8 @@ public:
|
|||
RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const;
|
||||
|
||||
private:
|
||||
const struct ip* ip4;
|
||||
const struct ip6_hdr* ip6;
|
||||
const struct ip* ip4 = nullptr;
|
||||
const struct ip6_hdr* ip6 = nullptr;
|
||||
const IPv6_Hdr_Chain* ip6_hdrs = nullptr;
|
||||
bool del;
|
||||
const IPv6_Hdr_Chain* ip6_hdrs;
|
||||
};
|
||||
|
|
26
src/IPAddr.h
26
src/IPAddr.h
|
@ -136,7 +136,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~IPAddr() { };
|
||||
~IPAddr() = default;
|
||||
|
||||
/**
|
||||
* Returns the address' family.
|
||||
|
@ -145,7 +145,7 @@ public:
|
|||
{
|
||||
if ( memcmp(in6.s6_addr, v4_mapped_prefix, 12) == 0 )
|
||||
return IPv4;
|
||||
else
|
||||
|
||||
return IPv6;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public:
|
|||
{
|
||||
if ( GetFamily() == IPv4 )
|
||||
return in6.s6_addr[12] == 224;
|
||||
else
|
||||
|
||||
return in6.s6_addr[0] == 0xff;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
if ( GetFamily() == IPv4 )
|
||||
return ((in6.s6_addr[12] == 0xff) && (in6.s6_addr[13] == 0xff)
|
||||
&& (in6.s6_addr[14] == 0xff) && (in6.s6_addr[15] == 0xff));
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -305,25 +305,25 @@ public:
|
|||
* will be returned in dotted representation, IPv6 addresses in
|
||||
* compressed hex.
|
||||
*/
|
||||
string AsString() const;
|
||||
std::string AsString() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the address suitable for inclusion
|
||||
* in an URI. For IPv4 addresses, this is the same as AsString(), but
|
||||
* IPv6 addresses are encased in square brackets.
|
||||
*/
|
||||
string AsURIString() const
|
||||
std::string AsURIString() const
|
||||
{
|
||||
if ( GetFamily() == IPv4 )
|
||||
return AsString();
|
||||
else
|
||||
|
||||
return string("[") + AsString() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a host-order, plain hex string representation of the address.
|
||||
*/
|
||||
string AsHexString() const;
|
||||
std::string AsHexString() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the address. This returns the
|
||||
|
@ -335,7 +335,7 @@ public:
|
|||
* Returns a reverse pointer name associated with the IP address.
|
||||
* For example, 192.168.0.1's reverse pointer is 1.0.168.192.in-addr.arpa.
|
||||
*/
|
||||
string PtrName() const;
|
||||
std::string PtrName() const;
|
||||
|
||||
/**
|
||||
* Comparison operator for IP address.
|
||||
|
@ -528,7 +528,7 @@ public:
|
|||
/**
|
||||
* Constructs a prefix 0/0.
|
||||
*/
|
||||
IPPrefix() : length(0) {}
|
||||
IPPrefix() = default;
|
||||
|
||||
/**
|
||||
* Constructs a prefix instance from an IPv4 address and a prefix
|
||||
|
@ -575,7 +575,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~IPPrefix() { }
|
||||
~IPPrefix() = default;
|
||||
|
||||
/**
|
||||
* Returns the prefix in the form of an IP address. The address will
|
||||
|
@ -625,7 +625,7 @@ public:
|
|||
* will be returned in dotted representation, IPv6 addresses in
|
||||
* compressed hex.
|
||||
*/
|
||||
string AsString() const;
|
||||
std::string AsString() const;
|
||||
|
||||
operator std::string() const { return AsString(); }
|
||||
|
||||
|
@ -715,5 +715,5 @@ public:
|
|||
|
||||
private:
|
||||
IPAddr prefix; // We store it as an address with the non-prefix bits masked out via Mask().
|
||||
uint8_t length; // The bit length of the prefix relative to full IPv6 addr.
|
||||
uint8_t length = 0; // The bit length of the prefix relative to full IPv6 addr.
|
||||
};
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
#include "Reporter.h"
|
||||
#include "util.h"
|
||||
|
||||
PriorityQueue::PriorityQueue(int initial_size)
|
||||
PriorityQueue::PriorityQueue(int initial_size) : max_heap_size(initial_size)
|
||||
{
|
||||
max_heap_size = initial_size;
|
||||
heap = new PQ_Element*[max_heap_size];
|
||||
peak_heap_size = heap_size = cumulative_num = 0;
|
||||
}
|
||||
|
||||
PriorityQueue::~PriorityQueue()
|
||||
|
|
|
@ -9,8 +9,8 @@ class PriorityQueue;
|
|||
|
||||
class PQ_Element {
|
||||
public:
|
||||
explicit PQ_Element(double t) { time = t; offset = -1; }
|
||||
virtual ~PQ_Element() { }
|
||||
explicit PQ_Element(double t) : time(t) {}
|
||||
virtual ~PQ_Element() = default;
|
||||
|
||||
double Time() const { return time; }
|
||||
|
||||
|
@ -20,9 +20,9 @@ public:
|
|||
void MinimizeTime() { time = -HUGE_VAL; }
|
||||
|
||||
protected:
|
||||
PQ_Element() { time = 0; offset = -1; }
|
||||
double time;
|
||||
int offset;
|
||||
PQ_Element() = default;
|
||||
double time = 0.0;
|
||||
int offset = -1;
|
||||
};
|
||||
|
||||
class PriorityQueue {
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
{
|
||||
if ( heap_size == 0 )
|
||||
return 0;
|
||||
else
|
||||
|
||||
return heap[0];
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,9 @@ protected:
|
|||
SetElement(bin2, t);
|
||||
}
|
||||
|
||||
PQ_Element** heap;
|
||||
int heap_size;
|
||||
int peak_heap_size;
|
||||
int max_heap_size;
|
||||
uint64_t cumulative_num;
|
||||
PQ_Element** heap = nullptr;
|
||||
int heap_size = 0;
|
||||
int peak_heap_size = 0;
|
||||
int max_heap_size = 0;
|
||||
uint64_t cumulative_num = 0;
|
||||
};
|
||||
|
|
|
@ -301,12 +301,12 @@ public:
|
|||
return (TypeType*) this;
|
||||
}
|
||||
|
||||
int IsSet() const
|
||||
bool IsSet() const
|
||||
{
|
||||
return tag == TYPE_TABLE && (YieldType() == 0);
|
||||
}
|
||||
|
||||
int IsTable() const
|
||||
bool IsTable() const
|
||||
{
|
||||
return tag == TYPE_TABLE && (YieldType() != 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue