mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
binpac: Fix LGTM findings
This commit is contained in:
parent
5d75f8ed6c
commit
f365c253a7
10 changed files with 30 additions and 23 deletions
|
@ -17,6 +17,7 @@ void Attr::init()
|
||||||
{
|
{
|
||||||
expr_ = 0;
|
expr_ = 0;
|
||||||
seqend_ = 0;
|
seqend_ = 0;
|
||||||
|
delete_expr_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attr::Attr(AttrType type)
|
Attr::Attr(AttrType type)
|
||||||
|
@ -40,6 +41,7 @@ Attr::Attr(AttrType type, ExprList *exprlist)
|
||||||
type_ = type;
|
type_ = type;
|
||||||
init();
|
init();
|
||||||
expr_ = new Expr(exprlist);
|
expr_ = new Expr(exprlist);
|
||||||
|
delete_expr_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attr::Attr(AttrType type, SeqEnd *seqend)
|
Attr::Attr(AttrType type, SeqEnd *seqend)
|
||||||
|
@ -50,6 +52,12 @@ Attr::Attr(AttrType type, SeqEnd *seqend)
|
||||||
seqend_ = seqend;
|
seqend_ = seqend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Attr::~Attr()
|
||||||
|
{
|
||||||
|
if ( delete_expr_ )
|
||||||
|
delete expr_;
|
||||||
|
}
|
||||||
|
|
||||||
LetAttr::LetAttr(FieldList *letfields)
|
LetAttr::LetAttr(FieldList *letfields)
|
||||||
: Attr(ATTR_LET)
|
: Attr(ATTR_LET)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
Attr(AttrType type, ExprList *exprlist);
|
Attr(AttrType type, ExprList *exprlist);
|
||||||
Attr(AttrType type, SeqEnd *seqend);
|
Attr(AttrType type, SeqEnd *seqend);
|
||||||
|
|
||||||
|
virtual ~Attr();
|
||||||
|
|
||||||
AttrType type() const { return type_; }
|
AttrType type() const { return type_; }
|
||||||
Expr *expr() const { return expr_; }
|
Expr *expr() const { return expr_; }
|
||||||
SeqEnd *seqend() const { return seqend_; }
|
SeqEnd *seqend() const { return seqend_; }
|
||||||
|
@ -47,6 +49,7 @@ protected:
|
||||||
AttrType type_;
|
AttrType type_;
|
||||||
Expr *expr_;
|
Expr *expr_;
|
||||||
SeqEnd *seqend_;
|
SeqEnd *seqend_;
|
||||||
|
bool delete_expr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LetAttr : public Attr
|
class LetAttr : public Attr
|
||||||
|
|
|
@ -436,22 +436,21 @@ void CaseField::GenParseCode(Output* out_cc, Env* env,
|
||||||
|
|
||||||
{
|
{
|
||||||
Env case_env(env, this);
|
Env case_env(env, this);
|
||||||
Env *env = &case_env;
|
|
||||||
|
|
||||||
type_->GenPreParsing(out_cc, env);
|
type_->GenPreParsing(out_cc, &case_env);
|
||||||
type_->GenParseCode(out_cc, env, data, 0);
|
type_->GenParseCode(out_cc, &case_env, data, 0);
|
||||||
if ( size_var )
|
if ( size_var )
|
||||||
{
|
{
|
||||||
out_cc->println("%s = %s;",
|
out_cc->println("%s = %s;",
|
||||||
env->LValue(size_var),
|
case_env.LValue(size_var),
|
||||||
type_->DataSize(out_cc, env, data).c_str());
|
type_->DataSize(out_cc, &case_env, data).c_str());
|
||||||
}
|
}
|
||||||
if ( type_->incremental_input() )
|
if ( type_->incremental_input() )
|
||||||
{
|
{
|
||||||
ASSERT(case_type()->parsing_complete_var());
|
ASSERT(case_type()->parsing_complete_var());
|
||||||
out_cc->println("%s = %s;",
|
out_cc->println("%s = %s;",
|
||||||
env->LValue(case_type()->parsing_complete_var()),
|
case_env.LValue(case_type()->parsing_complete_var()),
|
||||||
env->RValue(type_->parsing_complete_var()));
|
case_env.RValue(type_->parsing_complete_var()));
|
||||||
}
|
}
|
||||||
out_cc->println("}");
|
out_cc->println("}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ ConnDecl::~ConnDecl()
|
||||||
{
|
{
|
||||||
delete flows_[0];
|
delete flows_[0];
|
||||||
delete flows_[1];
|
delete flows_[1];
|
||||||
|
delete data_type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnDecl::AddBaseClass(vector<string> *base_classes) const
|
void ConnDecl::AddBaseClass(vector<string> *base_classes) const
|
||||||
|
|
|
@ -66,6 +66,7 @@ AnalyzerContextDecl::AnalyzerContextDecl(
|
||||||
AnalyzerContextDecl::~AnalyzerContextDecl()
|
AnalyzerContextDecl::~AnalyzerContextDecl()
|
||||||
{
|
{
|
||||||
delete context_name_id_;
|
delete context_name_id_;
|
||||||
|
delete param_type_;
|
||||||
delete_list(ContextFieldList, context_fields_);
|
delete_list(ContextFieldList, context_fields_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ ConstString::ConstString(const string &s)
|
||||||
int len = strlen(text) + 1;
|
int len = strlen(text) + 1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
char* s = new char[len];
|
char* new_s = new char[len];
|
||||||
|
|
||||||
// Skip leading quote.
|
// Skip leading quote.
|
||||||
for ( ++text; *text; ++text )
|
for ( ++text; *text; ++text )
|
||||||
|
@ -95,22 +95,22 @@ ConstString::ConstString(const string &s)
|
||||||
if ( *text == '\\' )
|
if ( *text == '\\' )
|
||||||
{
|
{
|
||||||
++text; // skip '\'
|
++text; // skip '\'
|
||||||
s[i++] = expand_escape(text);
|
new_s[i++] = expand_escape(text);
|
||||||
--text; // point to end of sequence
|
--text; // point to end of sequence
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s[i++] = *text;
|
new_s[i++] = *text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSERT(i < len);
|
ASSERT(i < len);
|
||||||
|
|
||||||
// Get rid of trailing quote.
|
// Get rid of trailing quote.
|
||||||
ASSERT(s[i-1] == '"');
|
ASSERT(new_s[i-1] == '"');
|
||||||
s[i-1] = '\0';
|
new_s[i-1] = '\0';
|
||||||
|
|
||||||
unescaped_ = s;
|
unescaped_ = new_s;
|
||||||
delete [] s;
|
delete [] new_s;
|
||||||
}
|
}
|
||||||
catch(EscapeException const &e)
|
catch(EscapeException const &e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ class DataPtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DataPtr(Env* env, const ID* arg_id, const int arg_off);
|
DataPtr(Env* env, const ID* arg_id, const int arg_off);
|
||||||
|
DataPtr(DataPtr const& x) { *this = x; }
|
||||||
|
|
||||||
DataPtr const &operator=(DataPtr const &x)
|
DataPtr const &operator=(DataPtr const &x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
}
|
}
|
||||||
~ID()
|
~ID()
|
||||||
{
|
{
|
||||||
delete locname;
|
delete [] locname;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(ID const &x) const { return name == x.Name(); }
|
bool operator==(ID const &x) const { return name == x.Name(); }
|
||||||
|
|
|
@ -8,9 +8,6 @@ namespace {
|
||||||
|
|
||||||
void GenLetEval(const ID *id, Expr *expr, string prefix, Output* out, Env* env)
|
void GenLetEval(const ID *id, Expr *expr, string prefix, Output* out, Env* env)
|
||||||
{
|
{
|
||||||
if ( expr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // private namespace
|
} // private namespace
|
||||||
|
|
|
@ -19,9 +19,6 @@ string PPSet::ToCode(Env *env)
|
||||||
string PPType::ToCode(Env *env)
|
string PPType::ToCode(Env *env)
|
||||||
{
|
{
|
||||||
Type *type = expr_->DataType(env);
|
Type *type = expr_->DataType(env);
|
||||||
if ( ! type )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return type->DataTypeStr();
|
return type->DataTypeStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue