diff --git a/CHANGES b/CHANGES index 6943702656..442cb06f11 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +4.2.0-dev.165 | 2021-09-14 18:39:34 -0700 + + * still more nit-squashing (Vern Paxson, Corelight) + + * avoiding using back() for an empty std::string (Vern Paxson, Corelight) + + * additional tweaks to address some compiler warnings (Vern Paxson, Corelight) + + * tweaks to address some compiler warnings (Vern Paxson, Corelight) + + * tweaks to address concerns flagged by Coverity (Vern Paxson, Corelight) + 4.2.0-dev.159 | 2021-09-14 13:00:50 -0700 * ignore_checksums_nets: Add test for multiple subnets (Arne Welzel, Corelight) diff --git a/VERSION b/VERSION index 21a84a9ebd..9f9866d054 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.0-dev.159 +4.2.0-dev.165 diff --git a/src/script_opt/GenIDDefs.cc b/src/script_opt/GenIDDefs.cc index 45ac43e3af..98a2dc2eee 100644 --- a/src/script_opt/GenIDDefs.cc +++ b/src/script_opt/GenIDDefs.cc @@ -450,7 +450,7 @@ void GenIDDefs::EndConfluenceBlock(bool no_orig) confluence_blocks.pop_back(); - int bb = barrier_blocks.back(); + auto bb = barrier_blocks.back(); if ( bb > 0 && confluence_blocks.size() == bb ) barrier_blocks.pop_back(); @@ -520,7 +520,7 @@ void GenIDDefs::TrackID(const ID* id, const ExprPtr& e) // Ensure we track this identifier across all relevant // confluence regions. - for ( int i = barrier_blocks.back(); i < confluence_blocks.size(); ++i ) + for ( auto i = barrier_blocks.back(); i < confluence_blocks.size(); ++i ) // Add one because modified_IDs includes outer non-confluence // block. modified_IDs[i+1].insert(id); diff --git a/src/script_opt/GenIDDefs.h b/src/script_opt/GenIDDefs.h index ea380962b8..a6b9204b48 100644 --- a/src/script_opt/GenIDDefs.h +++ b/src/script_opt/GenIDDefs.h @@ -99,7 +99,7 @@ private: // unseen confluence regions outer to those, and (2) they // can get quite deep due when inlining, so there are savings // to avoid having to track outer to them. - std::vector barrier_blocks; + std::vector barrier_blocks; // The following is parallel to confluence_blocks except // the front entry tracks identifiers at the outermost diff --git a/src/script_opt/IDOptInfo.cc b/src/script_opt/IDOptInfo.cc index 76d730b4a5..c5c29d2de2 100644 --- a/src/script_opt/IDOptInfo.cc +++ b/src/script_opt/IDOptInfo.cc @@ -71,7 +71,7 @@ void IDOptInfo::Clear() void IDOptInfo::DefinedAfter(const Stmt* s, const ExprPtr& e, const std::vector& conf_blocks, - int conf_start) + bro_uint_t conf_start) { if ( tracing ) printf("ID %s defined at %d: %s\n", trace_ID, s ? s->GetOptInfo()->stmt_num : NO_DEF, s ? obj_desc(s).c_str() : ""); @@ -174,7 +174,7 @@ void IDOptInfo::BranchBackTo(const Stmt* from, const Stmt* to, bool close_all) auto from_reg = ActiveRegion(); auto f_oi = from->GetOptInfo(); auto t_oi = to->GetOptInfo(); - auto t_r_ind = FindRegionBeforeIndex(t_oi->stmt_num); + bro_uint_t t_r_ind = FindRegionBeforeIndex(t_oi->stmt_num); auto& t_r = usage_regions[t_r_ind]; if ( from_reg && from_reg->DefinedAfter() != t_r.DefinedAfter() && @@ -327,7 +327,7 @@ void IDOptInfo::ConfluenceBlockEndsAfter(const Stmt* s, bool no_orig_flow) int num_regions = 0; - for ( auto i = 0; i < usage_regions.size(); ++i ) + for ( auto i = 0U; i < usage_regions.size(); ++i ) { auto& ur = usage_regions[i]; @@ -480,7 +480,7 @@ void IDOptInfo::EndRegionsAfter(int stmt_num, int level) int IDOptInfo::FindRegionBeforeIndex(int stmt_num) { int region_ind = NO_DEF; - for ( auto i = 0; i < usage_regions.size(); ++i ) + for ( auto i = 0U; i < usage_regions.size(); ++i ) { auto ur = usage_regions[i]; diff --git a/src/script_opt/IDOptInfo.h b/src/script_opt/IDOptInfo.h index e07ad320c9..73e52e55da 100644 --- a/src/script_opt/IDOptInfo.h +++ b/src/script_opt/IDOptInfo.h @@ -142,7 +142,7 @@ public: // conf_blocks may be empty). void DefinedAfter(const Stmt* s, const ExprPtr& e, const std::vector& conf_blocks, - int conf_start); + bro_uint_t conf_start); // Called upon encountering a "return" statement. void ReturnAt(const Stmt* s); diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index 25b795d0e5..0f35148ff6 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -484,7 +484,7 @@ void ZAMCompiler::ReMapFrame() frame1_to_frame2.resize(frame_layout1.size(), -1); managed_slotsI.clear(); - for ( unsigned int i = 0; i < insts1.size(); ++i ) + for ( bro_uint_t i = 0; i < insts1.size(); ++i ) { auto inst = insts1[i]; @@ -659,7 +659,7 @@ void ZAMCompiler::ReMapInterpreterFrame() remapped_intrp_frame_sizes[func] = next_interp_slot; } -void ZAMCompiler::ReMapVar(ID* id, int slot, int inst) +void ZAMCompiler::ReMapVar(ID* id, int slot, bro_uint_t inst) { // A greedy algorithm for this is to simply find the first suitable // frame slot. We do that with one twist: we also look for a @@ -686,9 +686,10 @@ void ZAMCompiler::ReMapVar(ID* id, int slot, int inst) // ZAM instructions are careful to allow operands and // assignment destinations to refer to the same slot. - if ( s.scope_end <= inst && s.is_managed == is_managed ) + if ( s.scope_end <= static_cast(inst) && + s.is_managed == is_managed ) { // It's compatible. - if ( s.scope_end == inst ) + if ( s.scope_end == static_cast(inst) ) { // It ends right on the money. apt_slot = i; break; @@ -727,7 +728,8 @@ void ZAMCompiler::ReMapVar(ID* id, int slot, int inst) void ZAMCompiler::CheckSlotAssignment(int slot, const ZInstI* inst) { - ASSERT(slot >= 0 && slot < frame_denizens.size()); + ASSERT(slot >= 0 && + static_cast(slot) < frame_denizens.size()); // We construct temporaries such that their values are never used // earlier than their definitions in loop bodies. For other @@ -766,7 +768,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst) if ( slot < 0 ) return; - ASSERT(slot < frame_denizens.size()); + ASSERT(static_cast(slot) < frame_denizens.size()); if ( denizen_beginning.count(slot) == 0 ) { @@ -952,9 +954,9 @@ ZInstI* ZAMCompiler::FirstLiveInst(ZInstI* i, bool follow_gotos) return nullptr; } -int ZAMCompiler::FirstLiveInst(int i, bool follow_gotos) +bro_uint_t ZAMCompiler::FirstLiveInst(bro_uint_t i, bool follow_gotos) { - int num_inspected = 0; + bro_uint_t num_inspected = 0; while ( i < insts1.size() ) { auto i0 = insts1[i]; @@ -982,7 +984,7 @@ int ZAMCompiler::FirstLiveInst(int i, bool follow_gotos) return i; } -void ZAMCompiler::KillInst(int i) +void ZAMCompiler::KillInst(bro_uint_t i) { auto inst = insts1[i]; @@ -1007,6 +1009,8 @@ void ZAMCompiler::KillInst(int i) if ( inst->IsUnconditionalBranch() ) { + ASSERT(t); + // No direct flow after this point ... unless we're // branching to the next immediate live instruction. auto after_inst = NextLiveInst(inst, true); @@ -1035,7 +1039,7 @@ void ZAMCompiler::KillInst(int i) } } -void ZAMCompiler::KillInsts(int i) +void ZAMCompiler::KillInsts(bro_uint_t i) { auto inst = insts1[i]; diff --git a/src/script_opt/ZAM/Branches.cc b/src/script_opt/ZAM/Branches.cc index 330e5cbd0f..63fd662ac9 100644 --- a/src/script_opt/ZAM/Branches.cc +++ b/src/script_opt/ZAM/Branches.cc @@ -78,7 +78,7 @@ ZInstI* ZAMCompiler::FindLiveTarget(ZInstI* goto_target) return goto_target; int idx = goto_target->inst_num; - ASSERT(idx >= 0 && idx <= insts1.size()); + ASSERT(idx >= 0 && idx <= int(insts1.size())); while ( idx < int(insts1.size()) && ! insts1[idx]->live ) ++idx; diff --git a/src/script_opt/ZAM/BuiltIn.cc b/src/script_opt/ZAM/BuiltIn.cc index 7ee89f40e6..1ee2f230fb 100644 --- a/src/script_opt/ZAM/BuiltIn.cc +++ b/src/script_opt/ZAM/BuiltIn.cc @@ -371,21 +371,25 @@ bool ZAMCompiler::BuiltIn_sub_bytes(const NameExpr* n, const ExprPList& args) break; case 0x4: // first argument a constant + ASSERT(c); z = ZInstI(OP_SUB_BYTES_VVVC, nslot, v3, v4, c); z.op_type = OP_VVVC; break; case 0x5: // first and third constant + ASSERT(c); z = ZInstI(OP_SUB_BYTES_VViC, nslot, v3, v4, c); z.op_type = OP_VVVC_I3; break; case 0x6: // first and second constant - flip! + ASSERT(c); z = ZInstI(OP_SUB_BYTES_ViVC, nslot, v4, v3, c); z.op_type = OP_VVVC_I3; break; case 0x7: // whole shebang + ASSERT(c); z = ZInstI(OP_SUB_BYTES_ViiC, nslot, v3, v4, c); z.op_type = OP_VVVC_I2_I3; break; diff --git a/src/script_opt/ZAM/Compile.h b/src/script_opt/ZAM/Compile.h index 7678797a63..990eaee88d 100644 --- a/src/script_opt/ZAM/Compile.h +++ b/src/script_opt/ZAM/Compile.h @@ -183,7 +183,7 @@ private: const ZAMStmt LoopOverVector(const ForStmt* f, const NameExpr* val); const ZAMStmt LoopOverString(const ForStmt* f, const Expr* e); - const ZAMStmt FinishLoop(const ZAMStmt iter_head, ZInstI iter_stmt, + const ZAMStmt FinishLoop(const ZAMStmt iter_head, ZInstI& iter_stmt, const Stmt* body, int iter_slot, bool is_table); @@ -450,7 +450,7 @@ private: // Computes the remapping for a variable currently in the given slot, // whose scope begins at the given instruction. - void ReMapVar(ID* id, int slot, int inst); + void ReMapVar(ID* id, int slot, bro_uint_t inst); // Look to initialize the beginning of local lifetime based on slot // assignment at instruction inst. @@ -494,12 +494,12 @@ private: // First form returns nil if there's nothing live after i. // Second form returns insts1.size() in that case. ZInstI* FirstLiveInst(ZInstI* i, bool follow_gotos = false); - int FirstLiveInst(int i, bool follow_gotos = false); + bro_uint_t FirstLiveInst(bro_uint_t i, bool follow_gotos = false); // Same, but not including i. ZInstI* NextLiveInst(ZInstI* i, bool follow_gotos = false) { - if ( i->inst_num == insts1.size() - 1 ) + if ( i->inst_num == static_cast(insts1.size()) - 1 ) return nullptr; return FirstLiveInst(insts1[i->inst_num + 1], follow_gotos); } @@ -511,12 +511,12 @@ private: // into insts1; any labels associated with it are transferred // to its next live successor, if any. void KillInst(ZInstI* i) { KillInst(i->inst_num); } - void KillInst(int i); + void KillInst(bro_uint_t i); // The same, but kills any successor instructions until finding // one that's labeled. void KillInsts(ZInstI* i) { KillInsts(i->inst_num); } - void KillInsts(int i); + void KillInsts(bro_uint_t i); // The first of these is used as we compile down to ZInstI's. // The second is the final intermediary code. They're separate diff --git a/src/script_opt/ZAM/Driver.cc b/src/script_opt/ZAM/Driver.cc index 76dd71057d..2d4f4abd25 100644 --- a/src/script_opt/ZAM/Driver.cc +++ b/src/script_opt/ZAM/Driver.cc @@ -315,7 +315,7 @@ void ZAMCompiler::RemapFrameDenizens(const std::vector& inst1_to_inst2) // the form "slotX = slotX". In that // case, look forward for the next viable // instruction. - while ( start < int(insts1.size()) && + while ( start < insts1.size() && inst1_to_inst2[start] == -1 ) ++start; diff --git a/src/script_opt/ZAM/Expr.cc b/src/script_opt/ZAM/Expr.cc index 90a08a46c5..13227b90af 100644 --- a/src/script_opt/ZAM/Expr.cc +++ b/src/script_opt/ZAM/Expr.cc @@ -105,6 +105,7 @@ const ZAMStmt ZAMCompiler::AppendToField(const NameExpr* n1, const NameExpr* n2, } else { + ASSERT(c); z = ZInstI(OP_APPENDTOFIELD_VCi, FrameSlot(n1), offset, c); z.op_type = OP_VVC_I2; } @@ -547,6 +548,8 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l, else if ( l_e0_n ) { + ASSERT(l_e1_c); + z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC, n1, l_e0_n, n2, l_e1_c); z.t2 = l_e0_n->GetType(); @@ -554,6 +557,8 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l, else if ( l_e1_n ) { + ASSERT(l_e0_c); + z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV, n1, l_e1_n, n2, l_e0_c); z.t2 = l_e1_n->GetType(); @@ -563,6 +568,9 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l, { // Ugh, both are constants. Assign first to // a temporary. + ASSERT(l_e0_c); + ASSERT(l_e1_c); + auto slot = TempForConst(l_e0_c); z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1), slot, FrameSlot(n2), l_e1_c); @@ -687,6 +695,8 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot, else { + ASSERT(c3); + auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC, n1->GetType()->Tag()); z = ZInstI(zop, Frame1Slot(n1, zop), @@ -911,15 +921,21 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n) z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt), n_slot, FrameSlot(n0)); else + { + ASSERT(c0); z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt), n_slot, c0); + } } else { if ( n0 ) z = ZInstI(OP_CALL1_V, FrameSlot(n0)); else + { + ASSERT(c0); z = ZInstI(OP_CALL1_C, c0); + } } z.t = arg0->GetType(); @@ -1170,7 +1186,7 @@ const ZAMStmt ZAMCompiler::RecordCoerce(const NameExpr* n, const Expr* e) z.aux = new ZInstAux(map_size); z.aux->map = map; - for ( auto i = 0; i < map_size; ++i ) + for ( auto i = 0U; i < map_size; ++i ) z.aux->Add(i, map[i], nullptr); // Mark the integer entries in z.aux as not being frame slots as usual. diff --git a/src/script_opt/ZAM/Gen-ZAM.cc b/src/script_opt/ZAM/Gen-ZAM.cc index 851d39c811..3dd42a0f98 100644 --- a/src/script_opt/ZAM/Gen-ZAM.cc +++ b/src/script_opt/ZAM/Gen-ZAM.cc @@ -923,7 +923,7 @@ void ZAM_ExprOpTemplate::Parse(const string& attr, const string& line, if ( words.size() == 1 ) g->Gripe("op-type needs arguments", line); - for ( auto i = 1; i < words.size(); ++i ) + for ( auto i = 1U; i < words.size(); ++i ) { auto& w_i = words[i]; if ( w_i.size() != 1 ) @@ -1023,7 +1023,7 @@ void ZAM_ExprOpTemplate::Instantiate() InstantiateC3(op_types); bool all_var = true; - for ( auto i = 1; i < op_types.size(); ++i ) + for ( auto i = 1U; i < op_types.size(); ++i ) if ( op_types[i] != ZAM_OT_VAR ) all_var = false; @@ -2101,7 +2101,7 @@ void ZAMGen::Emit(EmitTarget et, const string& s) fputs(s.c_str(), f); - if ( s.back() != '\n' && ! no_NL ) + if ( ! no_NL && (s.empty() || s.back() != '\n') ) fputs("\n", f); } @@ -2272,6 +2272,15 @@ bool ZAMGen::ParseTemplate() int main(int argc, char** argv) { - ZAMGen(argc, argv); - exit(0); + try + { + ZAMGen zg(argc, argv); + exit(0); + } + catch ( const std::regex_error& e ) + { + fprintf(stderr, "%s: regular expression error - %s\n", + argv[0], e.what()); + exit(1); + } } diff --git a/src/script_opt/ZAM/IterInfo.h b/src/script_opt/ZAM/IterInfo.h index 2af43dbc8a..33eac3e4ff 100644 --- a/src/script_opt/ZAM/IterInfo.h +++ b/src/script_opt/ZAM/IterInfo.h @@ -90,7 +90,7 @@ private: const TableVal* tv = nullptr; // Associated auxiliary information. - ZInstAux* aux; + ZInstAux* aux = nullptr; std::optional tbl_iter; std::optional tbl_end; diff --git a/src/script_opt/ZAM/Ops.in b/src/script_opt/ZAM/Ops.in index a94519c0fb..e1516bce99 100644 --- a/src/script_opt/ZAM/Ops.in +++ b/src/script_opt/ZAM/Ops.in @@ -791,13 +791,13 @@ internal-op Val-Is-In-Vector type VVV eval auto& vec = frame[z.v3].vector_val; auto ind = frame[z.v2].int_val; - frame[z.v1].int_val = ind >= 0 && ind < vec->Size(); + frame[z.v1].int_val = ind >= 0 && static_cast(ind) < vec->Size(); internal-op Const-Is-In-Vector type VCV eval auto& vec = frame[z.v2].vector_val; auto ind = z.c.int_val; - frame[z.v1].int_val = ind >= 0 && ind < vec->Size(); + frame[z.v1].int_val = ind >= 0 && static_cast(ind) < vec->Size(); expr-op Cond type VVVV @@ -902,7 +902,7 @@ eval EvalIndexVec(frame[z.v3].uint_val) macro EvalIndexVec(index) auto vv = frame[z.v2].vector_val->RawVec(); const auto& vec = *vv; - auto ind = index; + bro_uint_t ind = index; if ( ind >= vv->size() ) ZAM_run_time_error(z.loc, "no such index"); AssignV1(CopyVal(*vec[ind])) @@ -917,7 +917,7 @@ eval EvalIndexAnyVec(frame[z.v3].uint_val) macro EvalIndexAnyVec(index) auto vv = frame[z.v2].vector_val; - auto ind = index; + bro_uint_t ind = index; if ( ind >= vv->Size() ) ZAM_run_time_error(z.loc, "no such index"); AssignV1(ZVal(vv->ValAt(ind).release())) @@ -1749,7 +1749,7 @@ op CheckAnyLen op1-read type Vi eval auto v = frame[z.v1].list_val; - if ( v->Vals().size() != z.v2 ) + if ( v->Vals().size() != static_cast(z.v2) ) ZAM_run_time_error(z.loc, "mismatch in list lengths"); op Print diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 21f670d2e6..008c1a2dad 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -530,6 +530,7 @@ const ZAMStmt ZAMCompiler::ValueSwitch(const SwitchStmt* sw, const NameExpr* v, auto sv = cv->AsString()->Render(); std::string s(sv); new_str_cases[s] = case_body_start; + delete[] sv; break; } @@ -806,7 +807,7 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val) auto aux = new ZInstAux(0); - for ( int i = 0; i < loop_vars->length(); ++i ) + for ( auto i = 0; i < loop_vars->length(); ++i ) { auto id = (*loop_vars)[i]; @@ -897,6 +898,7 @@ const ZAMStmt ZAMCompiler::LoopOverString(const ForStmt* f, const Expr* e) } else { + ASSERT(c); z = ZInstI(OP_INIT_STRING_LOOP_VC, iter_slot, c); z.op_type = OP_VC_I1; } @@ -926,9 +928,9 @@ const ZAMStmt ZAMCompiler::Loop(const Stmt* body) return tail; } -const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head, ZInstI iter_stmt, - const Stmt* body, int iter_slot, - bool is_table) +const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head, + ZInstI& iter_stmt, const Stmt* body, + int iter_slot, bool is_table) { auto loop_iter = AddInst(iter_stmt); auto body_end = CompileStmt(body); diff --git a/src/script_opt/ZAM/ZBody.cc b/src/script_opt/ZAM/ZBody.cc index ab22b02e8d..050fe490ed 100644 --- a/src/script_opt/ZAM/ZBody.cc +++ b/src/script_opt/ZAM/ZBody.cc @@ -49,7 +49,8 @@ void report_ZOP_profile() // assigned value was missing (which we can only tell for managed types), // true otherwise. -static bool copy_vec_elem(VectorVal* vv, int ind, ZVal zv, const TypePtr& t) +static bool copy_vec_elem(VectorVal* vv, bro_uint_t ind, ZVal zv, + const TypePtr& t) { if ( vv->Size() <= ind ) vv->Resize(ind + 1); @@ -263,7 +264,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow) const int end_pc = ninst; // Return value, or nil if none. - const ZVal* ret_u; + const ZVal* ret_u = nullptr; // Type of the return value. If nil, then we don't have a value. TypePtr ret_type; diff --git a/src/script_opt/ZAM/ZInst.cc b/src/script_opt/ZAM/ZInst.cc index a4c3b0f8ff..cafe99079b 100644 --- a/src/script_opt/ZAM/ZInst.cc +++ b/src/script_opt/ZAM/ZInst.cc @@ -9,7 +9,7 @@ using std::string; namespace zeek::detail { -void ZInst::Dump(int inst_num, const FrameReMap* mappings) const +void ZInst::Dump(bro_uint_t inst_num, const FrameReMap* mappings) const { // printf("v%d ", n); @@ -170,6 +170,8 @@ int ZInst::NumFrameSlots() const case OP_VVVV: return 4; } + + return -1; } int ZInst::NumSlots() const @@ -208,9 +210,11 @@ int ZInst::NumSlots() const case OP_VVVV_I2_I3_I4: return 4; } + + return -1; } -string ZInst::VName(int n, int inst_num, const FrameReMap* mappings) const +string ZInst::VName(int n, bro_uint_t inst_num, const FrameReMap* mappings) const { if ( n > NumFrameSlots() ) return ""; @@ -221,7 +225,7 @@ string ZInst::VName(int n, int inst_num, const FrameReMap* mappings) const return ""; // Find which identifier manifests at this instruction. - ASSERT(slot >= 0 && slot < mappings->size()); + ASSERT(slot >= 0 && static_cast(slot) < mappings->size()); auto& map = (*mappings)[slot]; @@ -278,6 +282,8 @@ ValPtr ZInst::ConstVal() const case OP_VVVV_I2_I3_I4: return nullptr; } + + return nullptr; } string ZInst::ConstDump() const @@ -321,16 +327,18 @@ string ZInstI::VName(int n, const FrameMap* frame_ids, if ( remappings && live ) { // Find which identifier manifests at this instruction. - ASSERT(slot >= 0 && slot < remappings->size()); + ASSERT(slot >= 0 && + static_cast(slot) < remappings->size()); auto& map = (*remappings)[slot]; unsigned int i; + auto inst_num_u = static_cast(inst_num); for ( i = 0; i < map.id_start.size(); ++i ) { // See discussion for ZInst::VName. - if ( (n == 1 && map.id_start[i] > inst_num) || - (n > 1 && map.id_start[i] >= inst_num) ) + if ( (n == 1 && map.id_start[i] > inst_num_u) || + (n > 1 && map.id_start[i] >= inst_num_u) ) // Went too far. break; } @@ -431,6 +439,8 @@ bool ZInstI::AssignsToSlot1() const auto fl = op1_flavor[op]; return fl == OP1_WRITE || fl == OP1_READ_WRITE; } + + return false; } bool ZInstI::UsesSlot(int slot) const @@ -473,6 +483,8 @@ bool ZInstI::UsesSlot(int slot) const case OP_VVVV: return v1_match || v2 == slot || v3 == slot || v4 == slot; } + + return false; } bool ZInstI::UsesSlots(int& s1, int& s2, int& s3, int& s4) const @@ -538,6 +550,8 @@ bool ZInstI::UsesSlots(int& s1, int& s2, int& s3, int& s4) const return true; } + + return false; } void ZInstI::UpdateSlots(std::vector& slot_mapping) diff --git a/src/script_opt/ZAM/ZInst.h b/src/script_opt/ZAM/ZInst.h index ccdb5deddd..5db65bcc29 100644 --- a/src/script_opt/ZAM/ZInst.h +++ b/src/script_opt/ZAM/ZInst.h @@ -35,14 +35,14 @@ public: // The ZAM instruction number where a given identifier starts its // scope, parallel to "ids". - std::vector id_start; + std::vector id_start; // The current end of the frame slot's scope. Gets updated as // new IDs are added to share the slot. - int scope_end; + int scope_end = -1; // Whether this is a managed slot. - bool is_managed; + bool is_managed = false; }; using FrameReMap = std::vector; @@ -66,7 +66,7 @@ public: virtual ~ZInst() { } // Methods for printing out the instruction for debugging/maintenance. - void Dump(int inst_num, const FrameReMap* mappings) const; + void Dump(bro_uint_t inst_num, const FrameReMap* mappings) const; void Dump(const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4) const; @@ -75,7 +75,7 @@ public: // by its number within a larger set. "mappings" provides the // mappings used to translate raw slots to the corresponding // script variable(s). - std::string VName(int n, int inst_num, + std::string VName(int n, bro_uint_t inst_num, const FrameReMap* mappings) const; // Number of slots that refer to a frame element. These always @@ -98,7 +98,9 @@ public: // When an instruction has both frame slots and integer constants, // the former always come first, even if conceptually in the operation // the constant is an "earlier" operand. - int v1, v2, v3, v4; + // + // Initialized here to keep Coverity happy. + int v1 = -1, v2 = -1, v3 = -1, v4 = -1; ZVal c; // constant associated with instruction, if any diff --git a/src/script_opt/ZAM/ZOp.cc b/src/script_opt/ZAM/ZOp.cc index c3b7244098..81c3acf3cc 100644 --- a/src/script_opt/ZAM/ZOp.cc +++ b/src/script_opt/ZAM/ZOp.cc @@ -12,6 +12,8 @@ const char* ZOP_name(ZOp op) #include "zeek/ZAM-OpsNamesDefs.h" case OP_NOP: return "nop"; } + + return ""; } static const char* op_type_name(ZAMOpType ot) @@ -41,6 +43,8 @@ static const char* op_type_name(ZAMOpType ot) case OP_VVVV_I3_I4: return "VVVV_I3_I4"; case OP_VVVV_I2_I3_I4: return "VVVV_I2_I3_I4"; } + + return ""; }