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:
Jon Siwek 2020-02-27 14:24:55 -08:00
commit 646a2313ae
10 changed files with 167 additions and 165 deletions

20
CHANGES
View file

@ -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 3.2.0-dev.159 | 2020-02-26 19:51:24 -0800
* Pop global frame stack on exception. (Johanna Amann, Corelight) * Pop global frame stack on exception. (Johanna Amann, Corelight)

View file

@ -1 +1 @@
3.2.0-dev.159 3.2.0-dev.167

View file

@ -55,12 +55,8 @@ const char* expr_name(BroExprTag t)
return expr_names[int(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); SetLocationInfo(&start_location, &end_location);
} }
@ -69,14 +65,14 @@ Expr::~Expr()
Unref(type); 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 */) void Expr::Add(Frame* /* f */)
@ -113,14 +109,14 @@ BroType* Expr::InitType() const
return type->Ref(); 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 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); return check_and_promote(Eval(0), t, 1);
} }
int Expr::IsError() const bool Expr::IsError() const
{ {
return type && type->Tag() == TYPE_ERROR; return type && type->Tag() == TYPE_ERROR;
} }
@ -153,12 +149,12 @@ void Expr::SetError(const char* msg)
SetError(); SetError();
} }
int Expr::IsZero() const bool Expr::IsZero() const
{ {
return IsConst() && ExprVal()->IsZero(); return IsConst() && ExprVal()->IsZero();
} }
int Expr::IsOne() const bool Expr::IsOne() const
{ {
return IsConst() && ExprVal()->IsOne(); return IsConst() && ExprVal()->IsOne();
} }
@ -295,7 +291,7 @@ void NameExpr::Assign(Frame* f, Val* v)
f->SetElement(id, v); f->SetElement(id, v);
} }
int NameExpr::IsPure() const bool NameExpr::IsPure() const
{ {
return id->IsConst(); return id->IsConst();
} }
@ -414,7 +410,7 @@ Val* UnaryExpr::Eval(Frame* f) const
} }
} }
int UnaryExpr::IsPure() const bool UnaryExpr::IsPure() const
{ {
return op->IsPure(); return op->IsPure();
} }
@ -551,7 +547,7 @@ Val* BinaryExpr::Eval(Frame* f) const
return result; return result;
} }
int BinaryExpr::IsPure() const bool BinaryExpr::IsPure() const
{ {
return op1->IsPure() && op2->IsPure(); 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_int_t i1 = 0, i2 = 0, i3 = 0;
bro_uint_t u1 = 0, u2 = 0, u3 = 0; bro_uint_t u1 = 0, u2 = 0, u3 = 0;
double d1 = 0.0, d2 = 0.0, d3 = 0.0; double d1 = 0.0, d2 = 0.0, d3 = 0.0;
int is_integral = 0; bool is_integral = false;
int is_unsigned = 0; bool is_unsigned = false;
if ( it == TYPE_INTERNAL_INT ) if ( it == TYPE_INTERNAL_INT )
{ {
i1 = v1->InternalInt(); i1 = v1->InternalInt();
i2 = v2->InternalInt(); i2 = v2->InternalInt();
++is_integral; is_integral = true;
} }
else if ( it == TYPE_INTERNAL_UNSIGNED ) else if ( it == TYPE_INTERNAL_UNSIGNED )
{ {
u1 = v1->InternalUnsigned(); u1 = v1->InternalUnsigned();
u2 = v2->InternalUnsigned(); u2 = v2->InternalUnsigned();
++is_unsigned; is_unsigned = true;
} }
else if ( it == TYPE_INTERNAL_DOUBLE ) else if ( it == TYPE_INTERNAL_DOUBLE )
{ {
@ -858,7 +854,7 @@ Val* BinaryExpr::AddrFold(Val* v1, Val* v2) const
{ {
IPAddr a1 = v1->AsAddr(); IPAddr a1 = v1->AsAddr();
IPAddr a2 = v2->AsAddr(); IPAddr a2 = v2->AsAddr();
int result = 0; bool result = false;
switch ( tag ) { switch ( tag ) {
@ -893,7 +889,7 @@ Val* BinaryExpr::SubNetFold(Val* v1, Val* v2) const
const IPPrefix& n1 = v1->AsSubNet(); const IPPrefix& n1 = v1->AsSubNet();
const IPPrefix& n2 = v2->AsSubNet(); const IPPrefix& n2 = v2->AsSubNet();
bool result = ( n1 == n2 ) ? true : false; bool result = n1 == n2;
if ( tag == EXPR_NE ) if ( tag == EXPR_NE )
result = ! result; 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) ComplementExpr::ComplementExpr(Expr* arg_op) : UnaryExpr(EXPR_COMPLEMENT, arg_op)
@ -1605,8 +1601,8 @@ Val* BoolExpr::Eval(Frame* f) const
if ( ! v1 ) if ( ! v1 )
return 0; return 0;
int is_vec1 = is_vector(op1); bool is_vec1 = is_vector(op1);
int is_vec2 = is_vector(op2); bool is_vec2 = is_vector(op2);
// Handle scalar op scalar // Handle scalar op scalar
if ( ! is_vec1 && ! is_vec2 ) if ( ! is_vec1 && ! is_vec2 )
@ -2044,7 +2040,7 @@ Val* CondExpr::Eval(Frame* f) const
return result; return result;
} }
int CondExpr::IsPure() const bool CondExpr::IsPure() const
{ {
return op1->IsPure() && op2->IsPure() && op3->IsPure(); 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)); 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() ) if ( op1->Type()->IsSet() )
op2 = new SetConstructorExpr(op2->AsListExpr(), attr_copy); op2 = new SetConstructorExpr(op2->AsListExpr(), attr_copy);
@ -2289,11 +2285,8 @@ bool AssignExpr::TypeCheckArithmetics(TypeTag bt1, TypeTag bt2)
{ {
if ( ! IsArithmetic(bt2) ) if ( ! IsArithmetic(bt2) )
{ {
char err[512]; ExprError(fmt("assignment of non-arithmetic value to arithmetic (%s/%s)",
snprintf(err, sizeof(err), type_name(bt1), type_name(bt2)));
"assignment of non-arithmetic value to arithmetic (%s/%s)",
type_name(bt1), type_name(bt2));
ExprError(err);
return false; 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 ) if ( op1->Tag() == EXPR_NAME )
{ {
@ -2510,15 +2503,15 @@ int AssignExpr::IsRecordElement(TypeDecl* td) const
td->id = copy_string(n->Id()->Name()); td->id = copy_string(n->Id()->Name());
} }
return 1; return true;
}
else
return 0;
} }
int AssignExpr::IsPure() const return false;
}
bool AssignExpr::IsPure() const
{ {
return 0; return false;
} }
IndexSliceAssignExpr::IndexSliceAssignExpr(Expr* op1, Expr* op2, int is_init) 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() ) if ( IsError() )
return 1; // avoid cascading the error report return true; // avoid cascading the error report
// "add" only allowed if our type is "set". // "add" only allowed if our type is "set".
return op1->Type()->IsSet(); return op1->Type()->IsSet();
} }
int IndexExpr::CanDel() const bool IndexExpr::CanDel() const
{ {
if ( IsError() ) if ( IsError() )
return 1; // avoid cascading the error report return true; // avoid cascading the error report
return op1->Type()->Tag() == TYPE_TABLE; return op1->Type()->Tag() == TYPE_TABLE;
} }
@ -2993,7 +2986,7 @@ Expr* FieldExpr::MakeLvalue()
return new RefExpr(this); return new RefExpr(this);
} }
int FieldExpr::CanDel() const bool FieldExpr::CanDel() const
{ {
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL); return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
} }
@ -3212,7 +3205,7 @@ TableConstructorExpr::TableConstructorExpr(ListExpr* constructor_list,
} }
else else
{ {
if ( constructor_list->Exprs().length() == 0 ) if ( constructor_list->Exprs().empty() )
SetType(new TableType(new TypeList(base_type(TYPE_ANY)), 0)); SetType(new TableType(new TypeList(base_type(TYPE_ANY)), 0));
else else
{ {
@ -3324,7 +3317,7 @@ SetConstructorExpr::SetConstructorExpr(ListExpr* constructor_list,
} }
else else
{ {
if ( constructor_list->Exprs().length() == 0 ) if ( constructor_list->Exprs().empty() )
SetType(new ::SetType(new TypeList(base_type(TYPE_ANY)), 0)); SetType(new ::SetType(new TypeList(base_type(TYPE_ANY)), 0));
else else
SetType(init_type(constructor_list)); SetType(init_type(constructor_list));
@ -3441,7 +3434,7 @@ VectorConstructorExpr::VectorConstructorExpr(ListExpr* constructor_list,
} }
else else
{ {
if ( constructor_list->Exprs().length() == 0 ) if ( constructor_list->Exprs().empty() )
{ {
// vector(). // vector().
// By default, assign VOID type here. A vector with // 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 ) if ( td )
{ {
@ -3561,7 +3554,7 @@ int FieldAssignExpr::IsRecordElement(TypeDecl* td) const
td->id = copy_string(field_name.c_str()); td->id = copy_string(field_name.c_str());
} }
return 1; return true;
} }
void FieldAssignExpr::ExprDescribe(ODesc* d) const void FieldAssignExpr::ExprDescribe(ODesc* d) const
@ -4028,9 +4021,9 @@ ScheduleExpr::~ScheduleExpr()
Unref(event); Unref(event);
} }
int ScheduleExpr::IsPure() const bool ScheduleExpr::IsPure() const
{ {
return 0; return false;
} }
Val* ScheduleExpr::Eval(Frame* f) const Val* ScheduleExpr::Eval(Frame* f) const
@ -4304,7 +4297,7 @@ CallExpr::~CallExpr()
Unref(args); Unref(args);
} }
int CallExpr::IsPure() const bool CallExpr::IsPure() const
{ {
if ( IsError() ) if ( IsError() )
return 1; return 1;
@ -4614,22 +4607,22 @@ void ListExpr::Append(Expr* e)
((TypeList*) type)->Append(e->Type()->Ref()); ((TypeList*) type)->Append(e->Type()->Ref());
} }
int ListExpr::IsPure() const bool ListExpr::IsPure() const
{ {
for ( const auto& expr : exprs ) for ( const auto& expr : exprs )
if ( ! expr->IsPure() ) if ( ! expr->IsPure() )
return 0; return false;
return 1; return true;
} }
int ListExpr::AllConst() const bool ListExpr::AllConst() const
{ {
for ( const auto& expr : exprs ) for ( const auto& expr : exprs )
if ( ! expr->IsConst() ) if ( ! expr->IsConst() )
return 0; return false;
return 1; return true;
} }
Val* ListExpr::Eval(Frame* f) const Val* ListExpr::Eval(Frame* f) const
@ -4654,7 +4647,7 @@ Val* ListExpr::Eval(Frame* f) const
BroType* ListExpr::InitType() const BroType* ListExpr::InitType() const
{ {
if ( exprs.length() == 0 ) if ( exprs.empty() )
{ {
Error("empty list in untyped initialization"); Error("empty list in untyped initialization");
return 0; return 0;
@ -5321,7 +5314,7 @@ val_list* eval_list(Frame* f, const ListExpr* l)
return v; 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();
} }

View file

@ -16,7 +16,7 @@
using std::string; using std::string;
typedef enum { enum BroExprTag : int {
EXPR_ANY = -1, EXPR_ANY = -1,
EXPR_NAME, EXPR_CONST, EXPR_NAME, EXPR_CONST,
EXPR_CLONE, EXPR_CLONE,
@ -54,7 +54,7 @@ typedef enum {
EXPR_IS, EXPR_IS,
EXPR_INDEX_SLICE_ASSIGN, EXPR_INDEX_SLICE_ASSIGN,
#define NUM_EXPRS (int(EXPR_INDEX_SLICE_ASSIGN) + 1) #define NUM_EXPRS (int(EXPR_INDEX_SLICE_ASSIGN) + 1)
} BroExprTag; };
extern const char* expr_name(BroExprTag t); extern const char* expr_name(BroExprTag t);
@ -102,7 +102,7 @@ public:
// constitutes a record element, false otherwise. If the TypeDecl* // constitutes a record element, false otherwise. If the TypeDecl*
// is non-nil and the expression is a record element, fills in the // is non-nil and the expression is a record element, fills in the
// TypeDecl with a description of the element. // 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 // Returns a value corresponding to this expression interpreted
// as an initialization, or nil if the expression is inconsistent // as an initialization, or nil if the expression is inconsistent
@ -112,13 +112,13 @@ public:
virtual Val* InitVal(const BroType* t, Val* aggr) const; virtual Val* InitVal(const BroType* t, Val* aggr) const;
// True if the expression has no side effects, false otherwise. // 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. // 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). // True if the expression is in error (to alleviate error propagation).
int IsError() const; bool IsError() const;
// Mark expression as in error. // Mark expression as in error.
void SetError(); void SetError();
@ -129,15 +129,15 @@ public:
inline Val* ExprVal() const; inline Val* ExprVal() const;
// True if the expression is a constant zero, false otherwise. // 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. // 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, // True if the expression supports the "add" or "delete" operations,
// false otherwise. // false otherwise.
virtual int CanAdd() const; virtual bool CanAdd() const;
virtual int CanDel() const; virtual bool CanDel() const;
virtual void Add(Frame* f); // perform add operation virtual void Add(Frame* f); // perform add operation
virtual void Delete(Frame* f); // perform delete operation virtual void Delete(Frame* f); // perform delete operation
@ -149,8 +149,8 @@ public:
// Marks the expression as one requiring (or at least appearing // Marks the expression as one requiring (or at least appearing
// with) parentheses. Used for pretty-printing. // with) parentheses. Used for pretty-printing.
void MarkParen() { paren = 1; } void MarkParen() { paren = true; }
int IsParen() const { return paren; } bool IsParen() const { return paren; }
const ListExpr* AsListExpr() const const ListExpr* AsListExpr() const
{ {
@ -205,7 +205,7 @@ public:
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0; virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
protected: protected:
Expr() { type = 0; } Expr() = default;
explicit Expr(BroExprTag arg_tag); explicit Expr(BroExprTag arg_tag);
virtual void ExprDescribe(ODesc* d) const = 0; virtual void ExprDescribe(ODesc* d) const = 0;
@ -225,9 +225,9 @@ protected:
void RuntimeErrorWithCallStack(const std::string& msg) const; void RuntimeErrorWithCallStack(const std::string& msg) const;
BroExprTag tag; BroExprTag tag;
BroType* type; BroType* type = nullptr;
int paren; bool paren;
}; };
class NameExpr : public Expr { class NameExpr : public Expr {
@ -240,7 +240,7 @@ public:
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
void Assign(Frame* f, Val* v) override; void Assign(Frame* f, Val* v) override;
Expr* MakeLvalue() override; Expr* MakeLvalue() override;
int IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -276,7 +276,7 @@ public:
// vectors correctly as necessary. // vectors correctly as necessary.
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
int IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -297,7 +297,7 @@ public:
Expr* Op1() const { return op1; } Expr* Op1() const { return op1; }
Expr* Op2() const { return op2; } Expr* Op2() const { return op2; }
int IsPure() const override; bool IsPure() const override;
// BinaryExpr::Eval correctly handles vector types. Any child // BinaryExpr::Eval correctly handles vector types. Any child
// class that overrides Eval() should be modified to handle // class that overrides Eval() should be modified to handle
@ -366,7 +366,7 @@ public:
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
Val* DoSingleEval(Frame* f, Val* v) const; Val* DoSingleEval(Frame* f, Val* v) const;
int IsPure() const override; bool IsPure() const override;
}; };
class ComplementExpr : public UnaryExpr { class ComplementExpr : public UnaryExpr {
@ -490,7 +490,7 @@ public:
const Expr* Op3() const { return op3; } const Expr* Op3() const { return op3; }
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
int IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -520,9 +520,9 @@ public:
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override; void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
BroType* InitType() 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; Val* InitVal(const BroType* t, Val* aggr) const override;
int IsPure() const override; bool IsPure() const override;
protected: protected:
bool TypeCheck(attr_list* attrs = 0); bool TypeCheck(attr_list* attrs = 0);
@ -542,8 +542,8 @@ class IndexExpr : public BinaryExpr {
public: public:
IndexExpr(Expr* op1, ListExpr* op2, bool is_slice = false); IndexExpr(Expr* op1, ListExpr* op2, bool is_slice = false);
int CanAdd() const override; bool CanAdd() const override;
int CanDel() const override; bool CanDel() const override;
void Add(Frame* f) override; void Add(Frame* f) override;
void Delete(Frame* f) override; void Delete(Frame* f) override;
@ -575,7 +575,7 @@ public:
int Field() const { return field; } int Field() const { return field; }
const char* FieldName() const { return field_name; } const char* FieldName() const { return field_name; }
int CanDel() const override; bool CanDel() const override;
void Assign(Frame* f, Val* v) override; void Assign(Frame* f, Val* v) override;
void Delete(Frame* f) override; void Delete(Frame* f) override;
@ -677,7 +677,7 @@ public:
const char* FieldName() const { return field_name.c_str(); } const char* FieldName() const { return field_name.c_str(); }
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override; void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
int IsRecordElement(TypeDecl* td) const override; bool IsRecordElement(TypeDecl* td) const override;
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -758,7 +758,7 @@ public:
ScheduleExpr(Expr* when, EventExpr* event); ScheduleExpr(Expr* when, EventExpr* event);
~ScheduleExpr() override; ~ScheduleExpr() override;
int IsPure() const override; bool IsPure() const override;
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
@ -791,7 +791,7 @@ public:
Expr* Func() const { return func; } Expr* Func() const { return func; }
ListExpr* Args() const { return args; } ListExpr* Args() const { return args; }
int IsPure() const override; bool IsPure() const override;
Val* Eval(Frame* f) const override; Val* Eval(Frame* f) const override;
@ -861,10 +861,10 @@ public:
expr_list& Exprs() { return exprs; } expr_list& Exprs() { return exprs; }
// True if the entire list represents pure values. // True if the entire list represents pure values.
int IsPure() const override; bool IsPure() const override;
// True if the entire list represents constant values. // True if the entire list represents constant values.
int AllConst() const; bool AllConst() const;
Val* Eval(Frame* f) const override; 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 // Returns true if e1 is "greater" than e2 - here "greater" is just
// a heuristic, used with commutative operators to put them into // a heuristic, used with commutative operators to put them into
// a canonical form. // 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 // True if the given Val* has a vector type
inline bool is_vector(Expr* e) { return e->Type()->Tag() == TYPE_VECTOR; } inline bool is_vector(Expr* e) { return e->Type()->Tag() == TYPE_VECTOR; }

View file

@ -766,7 +766,7 @@ IPv6_Hdr_Chain* IPv6_Hdr_Chain::Copy(const ip6_hdr* new_hdr) const
{ {
reporter->InternalWarning("empty IPv6 header chain"); reporter->InternalWarning("empty IPv6 header chain");
delete rval; delete rval;
return 0; return nullptr;
} }
const u_char* new_data = (const u_char*)new_hdr; const u_char* new_data = (const u_char*)new_hdr;

View file

@ -148,11 +148,7 @@ public:
/** /**
* Initializes the header chain from an IPv6 header structure. * Initializes the header chain from an IPv6 header structure.
*/ */
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len) : IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len)
#ifdef ENABLE_MOBILE_IPV6
homeAddr(0),
#endif
finalDst(0)
{ Init(ip6, len, false); } { Init(ip6, len, false); }
~IPv6_Hdr_Chain(); ~IPv6_Hdr_Chain();
@ -236,23 +232,13 @@ protected:
// point to a fragment // point to a fragment
friend class FragReassembler; friend class FragReassembler;
IPv6_Hdr_Chain() : IPv6_Hdr_Chain() = default;
length(0),
#ifdef ENABLE_MOBILE_IPV6
homeAddr(0),
#endif
finalDst(0)
{}
/** /**
* Initializes the header chain from an IPv6 header structure, and replaces * Initializes the header chain from an IPv6 header structure, and replaces
* the first next protocol pointer field that points to a fragment header. * 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) : IPv6_Hdr_Chain(const struct ip6_hdr* ip6, uint16_t next, int len)
#ifdef ENABLE_MOBILE_IPV6
homeAddr(0),
#endif
finalDst(0)
{ Init(ip6, len, true, next); } { Init(ip6, len, true, next); }
/** /**
@ -282,20 +268,20 @@ protected:
/** /**
* The summation of all header lengths in the chain in bytes. * The summation of all header lengths in the chain in bytes.
*/ */
uint16_t length; uint16_t length = 0;
#ifdef ENABLE_MOBILE_IPV6 #ifdef ENABLE_MOBILE_IPV6
/** /**
* Home Address of the packet's source as defined by Mobile IPv6 (RFC 6275). * Home Address of the packet's source as defined by Mobile IPv6 (RFC 6275).
*/ */
IPAddr* homeAddr; IPAddr* homeAddr = nullptr;
#endif #endif
/** /**
* The final destination address in chain's first Routing header that has * The final destination address in chain's first Routing header that has
* non-zero segments left. * 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. * @param arg_del whether to take ownership of \a arg_ip4 pointer's memory.
*/ */
IP_Hdr(const struct ip* arg_ip4, bool arg_del) 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. * @param c an already-constructed header chain to take ownership of.
*/ */
IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del, int len, IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del, int len,
const IPv6_Hdr_Chain* c = 0) const IPv6_Hdr_Chain* c = nullptr)
: ip4(0), ip6(arg_ip6), del(arg_del), : ip6(arg_ip6), ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len)),
ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len)) del(arg_del)
{ {
} }
@ -397,7 +383,7 @@ public:
{ {
if ( ip4 ) if ( ip4 )
return ((const u_char*) ip4) + ip4->ip_hl * 4; return ((const u_char*) ip4) + ip4->ip_hl * 4;
else
return ((const u_char*) ip6) + ip6_hdrs->TotalLength(); return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
} }
@ -409,9 +395,9 @@ public:
const ip6_mobility* MobilityHeader() const const ip6_mobility* MobilityHeader() const
{ {
if ( ip4 ) if ( ip4 )
return 0; return nullptr;
else if ( (*ip6_hdrs)[ip6_hdrs->Size()-1]->Type() != IPPROTO_MOBILITY ) else if ( (*ip6_hdrs)[ip6_hdrs->Size()-1]->Type() != IPPROTO_MOBILITY )
return 0; return nullptr;
else else
return (const ip6_mobility*)(*ip6_hdrs)[ip6_hdrs->Size()-1]->Data(); return (const ip6_mobility*)(*ip6_hdrs)[ip6_hdrs->Size()-1]->Data();
} }
@ -425,7 +411,7 @@ public:
{ {
if ( ip4 ) if ( ip4 )
return ntohs(ip4->ip_len) - ip4->ip_hl * 4; return ntohs(ip4->ip_len) - ip4->ip_hl * 4;
else
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength(); 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). * Returns the length of the IP packet (length of headers and payload).
*/ */
uint32_t TotalLen() const 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). * Returns length of IP packet header (includes extension headers for IPv6).
@ -543,8 +534,8 @@ public:
RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const; RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const;
private: private:
const struct ip* ip4; const struct ip* ip4 = nullptr;
const struct ip6_hdr* ip6; const struct ip6_hdr* ip6 = nullptr;
const IPv6_Hdr_Chain* ip6_hdrs = nullptr;
bool del; bool del;
const IPv6_Hdr_Chain* ip6_hdrs;
}; };

View file

@ -136,7 +136,7 @@ public:
/** /**
* Destructor. * Destructor.
*/ */
~IPAddr() { }; ~IPAddr() = default;
/** /**
* Returns the address' family. * Returns the address' family.
@ -145,7 +145,7 @@ public:
{ {
if ( memcmp(in6.s6_addr, v4_mapped_prefix, 12) == 0 ) if ( memcmp(in6.s6_addr, v4_mapped_prefix, 12) == 0 )
return IPv4; return IPv4;
else
return IPv6; return IPv6;
} }
@ -161,7 +161,7 @@ public:
{ {
if ( GetFamily() == IPv4 ) if ( GetFamily() == IPv4 )
return in6.s6_addr[12] == 224; return in6.s6_addr[12] == 224;
else
return in6.s6_addr[0] == 0xff; return in6.s6_addr[0] == 0xff;
} }
@ -173,7 +173,7 @@ public:
if ( GetFamily() == IPv4 ) if ( GetFamily() == IPv4 )
return ((in6.s6_addr[12] == 0xff) && (in6.s6_addr[13] == 0xff) return ((in6.s6_addr[12] == 0xff) && (in6.s6_addr[13] == 0xff)
&& (in6.s6_addr[14] == 0xff) && (in6.s6_addr[15] == 0xff)); && (in6.s6_addr[14] == 0xff) && (in6.s6_addr[15] == 0xff));
else
return false; return false;
} }
@ -305,25 +305,25 @@ public:
* will be returned in dotted representation, IPv6 addresses in * will be returned in dotted representation, IPv6 addresses in
* compressed hex. * compressed hex.
*/ */
string AsString() const; std::string AsString() const;
/** /**
* Returns a string representation of the address suitable for inclusion * Returns a string representation of the address suitable for inclusion
* in an URI. For IPv4 addresses, this is the same as AsString(), but * in an URI. For IPv4 addresses, this is the same as AsString(), but
* IPv6 addresses are encased in square brackets. * IPv6 addresses are encased in square brackets.
*/ */
string AsURIString() const std::string AsURIString() const
{ {
if ( GetFamily() == IPv4 ) if ( GetFamily() == IPv4 )
return AsString(); return AsString();
else
return string("[") + AsString() + "]"; return string("[") + AsString() + "]";
} }
/** /**
* Returns a host-order, plain hex string representation of the address. * 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 * 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. * 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. * 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. * Comparison operator for IP address.
@ -528,7 +528,7 @@ public:
/** /**
* Constructs a prefix 0/0. * Constructs a prefix 0/0.
*/ */
IPPrefix() : length(0) {} IPPrefix() = default;
/** /**
* Constructs a prefix instance from an IPv4 address and a prefix * Constructs a prefix instance from an IPv4 address and a prefix
@ -575,7 +575,7 @@ public:
/** /**
* Destructor. * Destructor.
*/ */
~IPPrefix() { } ~IPPrefix() = default;
/** /**
* Returns the prefix in the form of an IP address. The address will * 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 * will be returned in dotted representation, IPv6 addresses in
* compressed hex. * compressed hex.
*/ */
string AsString() const; std::string AsString() const;
operator std::string() const { return AsString(); } operator std::string() const { return AsString(); }
@ -715,5 +715,5 @@ public:
private: private:
IPAddr prefix; // We store it as an address with the non-prefix bits masked out via Mask(). 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.
}; };

View file

@ -9,11 +9,9 @@
#include "Reporter.h" #include "Reporter.h"
#include "util.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]; heap = new PQ_Element*[max_heap_size];
peak_heap_size = heap_size = cumulative_num = 0;
} }
PriorityQueue::~PriorityQueue() PriorityQueue::~PriorityQueue()

View file

@ -9,8 +9,8 @@ class PriorityQueue;
class PQ_Element { class PQ_Element {
public: public:
explicit PQ_Element(double t) { time = t; offset = -1; } explicit PQ_Element(double t) : time(t) {}
virtual ~PQ_Element() { } virtual ~PQ_Element() = default;
double Time() const { return time; } double Time() const { return time; }
@ -20,9 +20,9 @@ public:
void MinimizeTime() { time = -HUGE_VAL; } void MinimizeTime() { time = -HUGE_VAL; }
protected: protected:
PQ_Element() { time = 0; offset = -1; } PQ_Element() = default;
double time; double time = 0.0;
int offset; int offset = -1;
}; };
class PriorityQueue { class PriorityQueue {
@ -35,7 +35,7 @@ public:
{ {
if ( heap_size == 0 ) if ( heap_size == 0 )
return 0; return 0;
else
return heap[0]; return heap[0];
} }
@ -89,9 +89,9 @@ protected:
SetElement(bin2, t); SetElement(bin2, t);
} }
PQ_Element** heap; PQ_Element** heap = nullptr;
int heap_size; int heap_size = 0;
int peak_heap_size; int peak_heap_size = 0;
int max_heap_size; int max_heap_size = 0;
uint64_t cumulative_num; uint64_t cumulative_num = 0;
}; };

View file

@ -301,12 +301,12 @@ public:
return (TypeType*) this; return (TypeType*) this;
} }
int IsSet() const bool IsSet() const
{ {
return tag == TYPE_TABLE && (YieldType() == 0); return tag == TYPE_TABLE && (YieldType() == 0);
} }
int IsTable() const bool IsTable() const
{ {
return tag == TYPE_TABLE && (YieldType() != 0); return tag == TYPE_TABLE && (YieldType() != 0);
} }