Change int_list in CCL.h to be a vector, fix uses of int_list to match

This commit is contained in:
Tim Wojtulewicz 2019-06-19 15:57:12 -07:00 committed by Jon Siwek
parent e25caa2666
commit a4e2cfa2be
7 changed files with 54 additions and 47 deletions

View file

@ -2,6 +2,8 @@
#include "zeek-config.h"
#include <algorithm>
#include "CCL.h"
#include "RE.h"
#include "DFA.h"
@ -30,14 +32,14 @@ void CCL::Add(int sym)
ptr_compat_int sym_p = ptr_compat_int(sym);
// Check to see if the character is already in the ccl.
for ( int i = 0; i < syms->length(); ++i )
if ( (*syms)[i] == sym_p )
for ( auto sym : *syms )
if ( sym == sym_p )
return;
syms->append(sym_p);
syms->push_back(sym_p);
}
void CCL::Sort()
{
syms->sort(int_list_cmp);
std::sort(syms->begin(), syms->end());
}

View file

@ -3,9 +3,10 @@
#ifndef ccl_h
#define ccl_h
#include <vector>
#include "List.h"
typedef List<ptr_compat_int> int_list;
typedef std::vector<ptr_compat_int> int_list;
class CCL {
public:
@ -25,7 +26,7 @@ public:
{ delete syms; syms = new_syms; }
unsigned int MemoryAllocation() const
{ return padded_sizeof(*this) + syms->MemoryAllocation(); }
{ return padded_sizeof(*this) + padded_sizeof(*syms) + pad_size(syms->size() * sizeof(int_list::value_type)); }
protected:
int_list* syms;

View file

@ -108,11 +108,11 @@ DFA_State* DFA_State::ComputeXtion(int sym, DFA_Machine* machine)
void DFA_State::AppendIfNew(int sym, int_list* sym_list)
{
for ( int i = 0; i < sym_list->length(); ++i )
if ( (*sym_list)[i] == sym )
for ( auto value : *sym_list )
if ( value == sym )
return;
sym_list->append(sym);
sym_list->push_back(sym);
}
NFA_state_list* DFA_State::SymFollowSet(int ec_sym, const EquivClass* ec)
@ -132,8 +132,8 @@ NFA_state_list* DFA_State::SymFollowSet(int ec_sym, const EquivClass* ec)
if ( ccl->IsNegated() )
{
int j;
for ( j = 0; j < syms->length(); ++j )
size_t j;
for ( j = 0; j < syms->size(); ++j )
{
// Loop through (sorted) negated
// character class, which has
@ -143,19 +143,19 @@ NFA_state_list* DFA_State::SymFollowSet(int ec_sym, const EquivClass* ec)
break;
}
if ( j >= syms->length() || (*syms)[j] > ec_sym )
if ( j >= syms->size() || (*syms)[j] > ec_sym )
// Didn't find ec_sym in ccl.
n->AddXtionsTo(ns);
continue;
}
for ( int j = 0; j < syms->length(); ++j )
for ( auto sym : *syms )
{
if ( (*syms)[j] > ec_sym )
if ( sym > ec_sym )
break;
if ( (*syms)[j] == ec_sym )
if ( sym == ec_sym )
{
n->AddXtionsTo(ns);
break;

View file

@ -52,11 +52,10 @@ void EquivClass::ConvertCCL(CCL* ccl)
int_list* c_syms = ccl->Syms();
int_list* new_syms = new int_list;
for ( int i = 0; i < c_syms->length(); ++i )
for ( auto sym : *c_syms )
{
int sym = (*c_syms)[i];
if ( IsRep(sym) )
new_syms->append(SymEquivClass(sym));
new_syms->push_back(SymEquivClass(sym));
}
ccl->ReplaceSyms(new_syms);
@ -95,18 +94,18 @@ void EquivClass::CCL_Use(CCL* ccl)
}
int_list* csyms = ccl->Syms();
for ( int i = 0; i < csyms->length(); /* no increment */ )
for ( size_t i = 0; i < csyms->size(); /* no increment */ )
{
int sym = (*csyms)[i];
int old_ec = bck[sym];
int new_ec = sym;
int j = i + 1;
size_t j = i + 1;
for ( int k = fwd[sym]; k && k < size; k = fwd[k] )
{ // look for the symbol in the character class
for ( ; j < csyms->length(); ++j )
for ( ; j < csyms->size(); ++j )
{
if ( (*csyms)[j] > k )
// Since the character class is sorted,
@ -131,7 +130,7 @@ void EquivClass::CCL_Use(CCL* ccl)
}
}
if ( j < csyms->length() && (*csyms)[j] == k )
if ( j < csyms->size() && (*csyms)[j] == k )
// We broke out of the above loop by finding
// an old companion - go to the next symbol.
continue;
@ -154,7 +153,7 @@ void EquivClass::CCL_Use(CCL* ccl)
fwd[new_ec] = ec_nil;
// Find next ccl member to process.
for ( ++i; i < csyms->length() && ccl_flags[i]; ++i )
for ( ++i; i < csyms->size() && ccl_flags[i]; ++i )
// Reset "doesn't need processing" flag.
ccl_flags[i] = 0;
}

View file

@ -149,7 +149,7 @@ int Specific_RE_Matcher::Compile(int lazy)
int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx)
{
if ( set.length() != idx.length() )
if ( (size_t)set.length() != idx.size() )
reporter->InternalError("compileset: lengths of sets differ");
rem = this;

View file

@ -25,6 +25,11 @@
uint32 RuleHdrTest::idcounter = 0;
static bool is_member_of(const int_list& l, int_list::value_type v)
{
return std::find(l.begin(), l.end(), v) != l.end();
}
RuleHdrTest::RuleHdrTest(Prot arg_prot, uint32 arg_offset, uint32 arg_size,
Comp arg_comp, maskedvalue_list* arg_vals)
{
@ -349,7 +354,7 @@ void RuleMatcher::BuildRegEx(RuleHdrTest* hdr_test, string_list* exprs,
{
Rule::Pattern* p = r->patterns[j];
exprs[p->type].append(p->pattern);
ids[p->type].append(p->id);
ids[p->type].push_back(p->id);
}
}
@ -374,7 +379,7 @@ void RuleMatcher::BuildRegEx(RuleHdrTest* hdr_test, string_list* exprs,
loop_over_list(child_exprs[i], j)
{
exprs[i].append(child_exprs[i][j]);
ids[i].append(child_ids[i][j]);
ids[i].push_back(child_ids[i][j]);
}
}
}
@ -406,7 +411,7 @@ void RuleMatcher::BuildPatternSets(RuleHdrTest::pattern_set_list* dst,
if ( i < exprs.length() )
{
group_exprs.append(exprs[i]);
group_ids.append(ids[i]);
group_ids.push_back(ids[i]);
}
if ( group_exprs.length() > sig_max_group_size ||
@ -920,7 +925,7 @@ void RuleMatcher::Match(RuleEndpointState* state, Rule::PatternType type,
DBG_LOG(DBG_RULES, "On current node");
// Skip if rule already fired for this connection.
if ( state->matched_rules.is_member(r->Index()) )
if ( is_member_of(state->matched_rules, r->Index()) )
continue;
// Remember that all patterns have matched.
@ -971,7 +976,7 @@ void RuleMatcher::ExecPureRules(RuleEndpointState* state, bool eos)
bool RuleMatcher::ExecRulePurely(Rule* r, BroString* s,
RuleEndpointState* state, bool eos)
{
if ( state->matched_rules.is_member(r->Index()) )
if ( is_member_of(state->matched_rules, r->Index()) )
return false;
DBG_LOG(DBG_RULES, "Checking rule %s purely", r->ID());
@ -1014,7 +1019,7 @@ bool RuleMatcher::EvalRuleConditions(Rule* r, RuleEndpointState* state,
if ( ! pc->negate )
{
if ( ! pc_state->matched_rules.is_member(pc->rule->Index()) )
if ( ! is_member_of(pc_state->matched_rules, pc->rule->Index()) )
// Precond rule has not matched yet.
return false;
}
@ -1024,7 +1029,7 @@ bool RuleMatcher::EvalRuleConditions(Rule* r, RuleEndpointState* state,
if ( ! eos )
return false;
if ( pc_state->matched_rules.is_member(pc->rule->Index()) )
if ( is_member_of(pc_state->matched_rules, pc->rule->Index()) )
return false;
}
}
@ -1041,11 +1046,11 @@ void RuleMatcher::ExecRuleActions(Rule* r, RuleEndpointState* state,
const u_char* data, int len, bool eos)
{
if ( state->opposite &&
state->opposite->matched_rules.is_member(r->Index()) )
is_member_of(state->opposite->matched_rules, r->Index()) )
// We have already executed the actions.
return;
state->matched_rules.append(r->Index());
state->matched_rules.push_back(r->Index());
loop_over_list(r->actions, i)
r->actions[i]->DoAction(r, state, data, len);
@ -1063,7 +1068,7 @@ void RuleMatcher::ExecRuleActions(Rule* r, RuleEndpointState* state,
void RuleMatcher::ExecRule(Rule* rule, RuleEndpointState* state, bool eos)
{
// Nothing to do if it has already matched.
if ( state->matched_rules.is_member(rule->Index()) )
if ( is_member_of(state->matched_rules, rule->Index()) )
return;
loop_over_list(state->hdr_tests, i)
@ -1135,10 +1140,10 @@ void RuleMatcher::PrintTreeDebug(RuleHdrTest* node)
RuleHdrTest::PatternSet* set = node->psets[i][j];
fprintf(stderr,
"[%d patterns in %s group %d from %d rules]\n",
"[%d patterns in %s group %d from %zu rules]\n",
set->patterns.length(),
Rule::TypeToString((Rule::PatternType) i), j,
set->ids.length());
set->ids.size());
}
}
@ -1234,9 +1239,9 @@ void RuleMatcher::DumpStateStats(BroFile* f, RuleHdrTest* hdr_test)
set->re->DFA()->NumStates(),
Rule::TypeToString((Rule::PatternType)i), j));
loop_over_list(set->ids, k)
for ( auto id : set->ids )
{
Rule* r = Rule::rule_table[set->ids[k] - 1];
Rule* r = Rule::rule_table[id - 1];
f->Write(fmt("%s ", r->ID()));
}

View file

@ -756,7 +756,7 @@ void do_atif(Expr* expr)
if ( ! val->AsBool() )
{
if_stack.append(current_depth);
if_stack.push_back(current_depth);
BEGIN(IGNORE);
}
}
@ -769,7 +769,7 @@ void do_atifdef(const char* id)
if ( ! (i = lookup_ID(id, current_module.c_str())) )
{
if_stack.append(current_depth);
if_stack.push_back(current_depth);
BEGIN(IGNORE);
}
@ -784,7 +784,7 @@ void do_atifndef(const char *id)
if ( (i = lookup_ID(id, current_module.c_str())) )
{
if_stack.append(current_depth);
if_stack.push_back(current_depth);
BEGIN(IGNORE);
}
@ -796,17 +796,17 @@ void do_atelse()
if ( current_depth == 0 )
reporter->Error("@else without @if...");
if ( if_stack.length() && current_depth > if_stack.last() )
if ( ! if_stack.empty() && current_depth > if_stack.back() )
return;
if ( YY_START == INITIAL )
{
if_stack.append(current_depth);
if_stack.push_back(current_depth);
BEGIN(IGNORE);
}
else
{
if_stack.get();
if_stack.pop_back();
BEGIN(INITIAL);
}
}
@ -816,10 +816,10 @@ void do_atendif()
if ( current_depth == 0 )
reporter->Error("unbalanced @if... @endif");
if ( current_depth == if_stack.last() )
if ( current_depth == if_stack.back() )
{
BEGIN(INITIAL);
if_stack.get();
if_stack.pop_back();
}
--current_depth;