diff --git a/src/Func.cc b/src/Func.cc index 6a85623ad5..7464f76ece 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -322,7 +322,7 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, auto n = bs.size(); ASSERT(n == priorities.size()); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) { Body b; b.stmts = std::move(bs[i]); diff --git a/src/script_opt/CPP/Attrs.cc b/src/script_opt/CPP/Attrs.cc index 5412daf813..e6361f2df3 100644 --- a/src/script_opt/CPP/Attrs.cc +++ b/src/script_opt/CPP/Attrs.cc @@ -86,9 +86,8 @@ void CPPCompile::GenAttrs(const AttributesPtr& attrs) AddInit(attrs); - for ( auto i = 0; i < avec.size(); ++i ) + for ( const auto& attr : avec ) { - const auto& attr = avec[i]; const auto& e = attr->GetExpr(); if ( ! e ) @@ -171,7 +170,7 @@ const char* CPPCompile::AttrName(const AttrPtr& attr) case ATTR_IS_ASSIGNED: return "ATTR_IS_ASSIGNED"; case ATTR_IS_USED: return "ATTR_IS_USED"; - case NUM_ATTRS: return ""; + default: return ""; } } diff --git a/src/script_opt/CPP/CPP-load.bif b/src/script_opt/CPP/CPP-load.bif index eafdcf232b..8260dfd012 100644 --- a/src/script_opt/CPP/CPP-load.bif +++ b/src/script_opt/CPP/CPP-load.bif @@ -4,6 +4,8 @@ %%{ // C segment +#include +# #include "zeek/Reporter.h" #include "zeek/script_opt/ScriptOpt.h" #include "zeek/script_opt/CPP/Func.h" @@ -22,7 +24,7 @@ function load_CPP%(h: count%): bool if ( cb == detail::standalone_callbacks.end() ) { - reporter->Error("load of non-existing C++ code (%llu)", h); + reporter->Error("load of non-existing C++ code (%" PRIu64 ")", h); return zeek::val_mgr->False(); } diff --git a/src/script_opt/CPP/Consts.cc b/src/script_opt/CPP/Consts.cc index 1a1ab29528..e6af4c4c84 100644 --- a/src/script_opt/CPP/Consts.cc +++ b/src/script_opt/CPP/Consts.cc @@ -233,14 +233,14 @@ void CPPCompile::AddRecordConstant(const ValPtr& v, string& const_name) auto r = cast_intrusive(v); auto n = r->NumFields(); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) { const auto& r_i = r->GetField(i); if ( r_i ) { auto r_i_c = BuildConstant(v, r_i); - AddInit(v, const_name + "->Assign(" + Fmt(i) + + AddInit(v, const_name + "->Assign(" + Fmt(static_cast(i)) + ", " + r_i_c + ");"); } } @@ -282,7 +282,7 @@ void CPPCompile::AddVectorConstant(const ValPtr& v, string& const_name) auto vv = cast_intrusive(v); auto n = vv->Size(); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) { const auto& v_i = vv->ValAt(i); auto v_i_c = BuildConstant(v, v_i); diff --git a/src/script_opt/CPP/DeclFunc.cc b/src/script_opt/CPP/DeclFunc.cc index 0189b81ac7..02674029ca 100644 --- a/src/script_opt/CPP/DeclFunc.cc +++ b/src/script_opt/CPP/DeclFunc.cc @@ -19,7 +19,7 @@ void CPPCompile::DeclareFunc(const FuncInfo& func) auto fname = Canonicalize(BodyName(func).c_str()) + "_zf"; auto pf = func.Profile(); auto f = func.Func(); - auto body = func.Body(); + const auto& body = func.Body(); auto priority = func.Priority(); DeclareSubclass(f->GetType(), pf, fname, body, priority, nullptr, @@ -133,7 +133,7 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf, body_hashes[fname] = h; body_priorities[fname] = priority; body_names.emplace(body.get(), fname); - names_to_bodies.emplace(move(fname), body.get()); + names_to_bodies.emplace(fname, body.get()); total_hash = merge_p_hashes(total_hash, h); } diff --git a/src/script_opt/CPP/Driver.cc b/src/script_opt/CPP/Driver.cc index 0af00b7063..92a8e21cd6 100644 --- a/src/script_opt/CPP/Driver.cc +++ b/src/script_opt/CPP/Driver.cc @@ -63,7 +63,9 @@ void CPPCompile::Compile() // as a way to identify this compilation. Only germane when doing // incremental compilation (particularly of the test suite). char buf[8192]; - getcwd(buf, sizeof buf); + if ( ! getcwd(buf, sizeof buf) ) + reporter->FatalError("getcwd failed: %s", strerror(errno)); + working_dir = buf; if ( update && addl_tag > 0 && CheckForCollisions() ) @@ -212,7 +214,7 @@ void CPPCompile::RegisterCompiledBody(const string& f) // Build up an initializer of the events relevant to the function. string events; if ( body_events.count(f) > 0 ) - for ( auto e : body_events[f] ) + for ( const auto& e : body_events[f] ) { if ( events.size() > 0 ) events += ", "; diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index 9fd36da203..b21d12b77d 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -638,7 +638,7 @@ string CPPCompile::GenSetConstructorExpr(const Expr* e) { auto sc = static_cast(e); const auto& t = sc->GetType(); - auto attrs = sc->GetAttrs(); + const auto& attrs = sc->GetAttrs(); string attr_tags; string attr_vals; @@ -654,7 +654,7 @@ string CPPCompile::GenTableConstructorExpr(const Expr* e) { auto tc = static_cast(e); const auto& t = tc->GetType(); - auto attrs = tc->GetAttrs(); + const auto& attrs = tc->GetAttrs(); string attr_tags; string attr_vals; @@ -1126,7 +1126,7 @@ string CPPCompile::GenIntVector(const vector& vec) { string res("{ "); - for ( auto i = 0; i < vec.size(); ++i ) + for ( auto i = 0u; i < vec.size(); ++i ) { res += Fmt(vec[i]); diff --git a/src/script_opt/CPP/Func.cc b/src/script_opt/CPP/Func.cc index 7267d83e3d..9c7c8c7a36 100644 --- a/src/script_opt/CPP/Func.cc +++ b/src/script_opt/CPP/Func.cc @@ -36,9 +36,8 @@ broker::expected CPPLambdaFunc::SerializeClosure() const broker::vector body; - for ( int i = 0; i < vals.size(); ++i ) + for ( const auto& val : vals ) { - const auto& val = vals[i]; auto expected = Broker::detail::val_to_data(val.get()); if ( ! expected ) return broker::ec::invalid_data; diff --git a/src/script_opt/CPP/GenFunc.cc b/src/script_opt/CPP/GenFunc.cc index 38e3a04e71..4889c81f1c 100644 --- a/src/script_opt/CPP/GenFunc.cc +++ b/src/script_opt/CPP/GenFunc.cc @@ -19,7 +19,7 @@ void CPPCompile::CompileFunc(const FuncInfo& func) auto fname = Canonicalize(BodyName(func).c_str()) + "_zf"; auto pf = func.Profile(); auto f = func.Func(); - auto body = func.Body(); + const auto& body = func.Body(); DefineBody(f->GetType(), pf, fname, body, nullptr, f->Flavor()); } @@ -223,7 +223,7 @@ string CPPCompile::BodyName(const FuncInfo& func) // Make the name distinct-per-body. - int i; + size_t i; for ( i = 0; i < bodies.size(); ++i ) if ( bodies[i].stmts == body ) break; @@ -231,7 +231,7 @@ string CPPCompile::BodyName(const FuncInfo& func) if ( i >= bodies.size() ) reporter->InternalError("can't find body in CPPCompile::BodyName"); - return fname + "__" + Fmt(i); + return fname + "__" + Fmt(static_cast(i)); } string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) @@ -258,7 +258,7 @@ string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) if ( ! param_any && arg_any ) expr_gen = GenericValPtrToGT(expr_gen, param_t, GEN_NATIVE); - gen = gen + expr_gen; + gen += expr_gen; if ( i < n - 1 ) gen += ", "; } diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index 0335d86f43..40f7e9da4e 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -161,7 +161,7 @@ void CPPCompile::GenFuncVarInits() string hashes = "{"; - for ( auto b : bodies ) + for ( const auto& b : bodies ) { auto body = b.stmts.get(); diff --git a/src/script_opt/CPP/RuntimeOps.cc b/src/script_opt/CPP/RuntimeOps.cc index 76b3317cb6..2e21f7dfdf 100644 --- a/src/script_opt/CPP/RuntimeOps.cc +++ b/src/script_opt/CPP/RuntimeOps.cc @@ -31,7 +31,7 @@ ListValPtr index_val__CPP(vector indices) // In the future, we could provide N versions of this that // unroll the loop. - for ( auto i : indices ) + for ( const auto& i : indices ) ind_v->Append(i); return ind_v; @@ -61,7 +61,7 @@ ValPtr index_string__CPP(const StringValPtr& svp, vector indices) ValPtr set_event__CPP(IDPtr g, ValPtr v, EventHandlerPtr& gh) { - g->SetVal(move(v)); + g->SetVal(v); gh = event_registry->Register(g->Name()); return v; } @@ -116,15 +116,15 @@ ValPtr assign_to_index__CPP(T v1, ValPtr v2, ValPtr v3) ValPtr assign_to_index__CPP(TableValPtr v1, ValPtr v2, ValPtr v3) { - return assign_to_index__CPP(v1, v2, v3); + return assign_to_index__CPP(std::move(v1), std::move(v2), std::move(v3)); } ValPtr assign_to_index__CPP(VectorValPtr v1, ValPtr v2, ValPtr v3) { - return assign_to_index__CPP(v1, v2, v3); + return assign_to_index__CPP(std::move(v1), std::move(v2), std::move(v3)); } ValPtr assign_to_index__CPP(StringValPtr v1, ValPtr v2, ValPtr v3) { - return assign_to_index__CPP(v1, v2, v3); + return assign_to_index__CPP(std::move(v1), std::move(v2), std::move(v3)); } void add_element__CPP(TableValPtr aggr, ListValPtr indices) @@ -172,7 +172,7 @@ TableValPtr set_constructor__CPP(vector elements, TableTypePtr t, auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals)); auto aggr = make_intrusive(move(t), move(attrs)); - for ( const auto& elem : elements ) + for ( auto& elem : elements ) aggr->Assign(move(elem), nullptr); return aggr; @@ -188,7 +188,7 @@ TableValPtr table_constructor__CPP(vector indices, vector vals, auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals)); auto aggr = make_intrusive(move(t), move(attrs)); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) { auto v = check_and_promote(vals[i], yt, true); if ( v ) @@ -205,7 +205,7 @@ RecordValPtr record_constructor__CPP(vector vals, RecordTypePtr t) rv->Reserve(n); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) rv->Assign(i, vals[i]); return rv; @@ -216,7 +216,7 @@ VectorValPtr vector_constructor__CPP(vector vals, VectorTypePtr t) auto vv = make_intrusive(move(t)); auto n = vals.size(); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) vv->Assign(i, vals[i]); return vv; diff --git a/src/script_opt/CPP/Types.cc b/src/script_opt/CPP/Types.cc index 369bb0414a..68fdf48d11 100644 --- a/src/script_opt/CPP/Types.cc +++ b/src/script_opt/CPP/Types.cc @@ -140,10 +140,10 @@ void CPPCompile::ExpandTypeVar(const TypePtr& t) void CPPCompile::ExpandListTypeVar(const TypePtr& t, string& tn) { - auto tl = t->AsTypeList()->GetTypes(); + const auto& tl = t->AsTypeList()->GetTypes(); auto t_name = tn + "->AsTypeList()"; - for ( auto i = 0; i < tl.size(); ++i ) + for ( auto i = 0u; i < tl.size(); ++i ) AddInit(t, t_name + "->Append(" + GenTypeName(tl[i]) + ");"); } @@ -208,7 +208,7 @@ void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, string& tn) auto f = t->AsFuncType(); auto args_type_accessor = GenTypeName(f->Params()); - auto yt = f->Yield(); + const auto& yt = f->Yield(); string yield_type_accessor; @@ -447,9 +447,9 @@ void CPPCompile::RegisterType(const TypePtr& tp) void CPPCompile::RegisterListType(const TypePtr& t) { - auto tl = t->AsTypeList()->GetTypes(); + const auto& tl = t->AsTypeList()->GetTypes(); - for ( auto i = 0; i < tl.size(); ++i ) + for ( auto i = 0u; i < tl.size(); ++i ) { NoteNonRecordInitDependency(t, tl[i]); RegisterType(tl[i]); diff --git a/src/script_opt/CPP/Vars.cc b/src/script_opt/CPP/Vars.cc index d1d753a39c..0cf5e668c5 100644 --- a/src/script_opt/CPP/Vars.cc +++ b/src/script_opt/CPP/Vars.cc @@ -241,7 +241,7 @@ string CPPCompile::Canonicalize(const char* name) const if ( c == ':' || c == '-' ) c = '_'; - cname = cname + c; + cname += c; } // Add a trailing '_' to avoid conflicts with C++ keywords. diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index 555cb0e62d..aad6cc3004 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -483,7 +483,7 @@ void ProfileFuncs::MergeInProfile(ProfileFunc* pf) (void) HashType(t->AsTypeType()->GetType()); auto& init_exprs = g->GetInitExprs(); - for ( auto i_e : init_exprs ) + for ( const auto& i_e : init_exprs ) if ( i_e ) { pending_exprs.push_back(i_e.get()); @@ -550,7 +550,7 @@ void ProfileFuncs::TraverseValue(const ValPtr& v) auto r = cast_intrusive(v); auto n = r->NumFields(); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) TraverseValue(r->GetField(i)); } break; @@ -583,7 +583,7 @@ void ProfileFuncs::TraverseValue(const ValPtr& v) auto vv = cast_intrusive(v); auto n = vv->Size(); - for ( auto i = 0; i < n; ++i ) + for ( auto i = 0u; i < n; ++i ) TraverseValue(vv->ValAt(i)); } break; diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 3a8ec83df9..ff20df0800 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -334,7 +334,7 @@ void analyze_scripts() printf("\nAdditional C++ script bodies available:\n"); int addl = 0; - for ( auto s : compiled_scripts ) + for ( const auto& s : compiled_scripts ) if ( already_reported.count(s.first) == 0 ) { printf("%s body (hash %llu)\n",