]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Fix/Suppress remaining Cppcheck warnings (#291)
authorKonstantinos Margaritis <markos@users.noreply.github.com>
Mon, 27 May 2024 09:23:02 +0000 (12:23 +0300)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 09:23:02 +0000 (12:23 +0300)
Fix/suppress the following cppcheck warnings:

* arithOperationsOnVoidPointer
* uninitMember
* const*
* shadowVariable
* assignmentIntegerToAddress
* containerOutOfBounds
* pointer-related warnings in Ragel source
* missingOverride
* memleak
* knownConditionTrueFalse
* noExplicitConstructor
* invalidPrintfArgType_sint
* useStlAlgorithm
* cstyleCast
* clarifyCondition
* VSX-related cstyleCast
* unsignedLessThanZero

Furthermore, we added a suppression list to be used, which also includes the following:
* missingIncludeSystem
* missingInclude
* unmatchedSuppression

78 files changed:
benchmarks/benchmarks.cpp
benchmarks/benchmarks.hpp
cppcheck-suppression-list.txt [new file with mode: 0644]
src/fdr/fdr_compile_util.cpp
src/fdr/fdr_dump.cpp
src/hwlm/hwlm_build.cpp
src/nfa/goughcompile.cpp
src/nfa/goughcompile_dump.cpp
src/nfa/goughcompile_reg.cpp
src/nfa/goughdump.cpp
src/nfa/lbr_common_impl.h
src/nfa/limex_common_impl.h
src/nfa/limex_compile.cpp
src/nfa/limex_exceptional.h
src/nfa/mcclellancompile_util.cpp
src/nfa/mcclellandump.cpp
src/nfa/mcsheng_dump.cpp
src/nfa/mpvcompile.cpp
src/nfa/nfa_build_util.cpp
src/nfa/nfa_dump_internal.cpp
src/nfa/rdfa.cpp
src/nfa/rdfa.h
src/nfa/rdfa_merge.cpp
src/nfa/shengdump.cpp
src/nfa/tamarama.c
src/nfa/tamaramacompile.cpp
src/nfagraph/ng_equivalence.cpp
src/nfagraph/ng_holder.h
src/nfagraph/ng_limex.cpp
src/nfagraph/ng_limex_accel.cpp
src/nfagraph/ng_literal_analysis.cpp
src/nfagraph/ng_literal_decorated.cpp
src/nfagraph/ng_mcclellan.cpp
src/nfagraph/ng_misc_opt.cpp
src/nfagraph/ng_region.h
src/nfagraph/ng_repeat.cpp
src/nfagraph/ng_restructuring.cpp
src/nfagraph/ng_util.cpp
src/parser/Parser.rl
src/parser/buildstate.cpp
src/parser/control_verbs.rl
src/parser/position_info.h
src/parser/prefilter.cpp
src/rose/rose_build_add.cpp
src/rose/rose_build_add_mask.cpp
src/rose/rose_build_bytecode.cpp
src/rose/rose_build_compile.cpp
src/rose/rose_build_dump.cpp
src/rose/rose_build_exclusive.cpp
src/rose/rose_build_misc.cpp
src/rose/rose_build_role_aliasing.cpp
src/rose/rose_build_width.cpp
src/som/slot_manager_dump.cpp
src/util/arch/arm/simd_utils.h
src/util/arch/ppc64el/simd_utils.h
src/util/depth.h
src/util/dump_charclass.cpp
src/util/flat_containers.h
src/util/graph_undirected.h
src/util/insertion_ordered.h
src/util/partitioned_set.h
src/util/supervector/arch/ppc64el/impl.cpp
src/util/uniform_ops.h
tools/hsbench/engine_chimera.h
tools/hsbench/engine_hyperscan.h
tools/hsbench/engine_pcre.h
tools/hsbench/main.cpp
tools/hsdump/main.cpp
unit/hyperscan/test_util.cpp
unit/internal/charreach.cpp
unit/internal/fdr.cpp
unit/internal/fdr_flood.cpp
unit/internal/flat_map.cpp
unit/internal/flat_set.cpp
unit/internal/multi_bit.cpp
unit/internal/multi_bit_compress.cpp
unit/internal/repeat.cpp
util/ng_corpus_generator.cpp

index c4c93699c0fff687c72623aad4849c1d24657b5c..81402994448c27909746f5fa22524dbca7c467dc 100644 (file)
@@ -278,7 +278,7 @@ int main(){
             // we imitate the noodle unit tests
             std::string str;
             const size_t char_len = 5;
-            str.resize(char_len + 1);
+            str.resize(char_len + 2);
             for (size_t j = 0; j < char_len; j++) {
                 srand(time(NULL));
                 int key = rand() % +36;
index 968743180e2d0f72c2f0e302432d59b22483af07..fb8698ed750a4705cdf566b836e03bb5f35a2e54 100644 (file)
@@ -61,7 +61,7 @@ public:
     std::vector<u8> buf;
 
     // Noodle
-    struct hs_scratch scratch;
+    struct hs_scratch scratch{};
     ue2::bytecode_ptr<noodTable> nt;
 
     MicroBenchmark(char const *label_, size_t size_)
diff --git a/cppcheck-suppression-list.txt b/cppcheck-suppression-list.txt
new file mode 100644 (file)
index 0000000..aa7fedc
--- /dev/null
@@ -0,0 +1,12 @@
+unknownMacro:*gtest-all.cc
+knownConditionTrueFalse:*Parser.rl
+knownConditionTrueFalse:*Parser.cpp
+variableScope:*Parser.rl
+unreadVariable:*control_verbs.cpp
+assertWithSideEffect
+syntaxError
+internalError
+checkersReport
+missingInclude
+missingIncludeSystem
+unmatchedSuppression
index 350a096742c35697f55008338125d1910766492e..ff2275f03f24ad54c737f1801c9ab4d605c971e6 100644 (file)
@@ -39,6 +39,7 @@ namespace ue2 {
 size_t maxLen(const vector<hwlmLiteral> &lits) {
     size_t rv = 0;
     for (const auto &lit : lits) {
+        // cppcheck-suppress useStlAlgorithm
         rv = max(rv, lit.s.size());
     }
     return rv;
index 1390c4f203b0809de73228c42c17f099a80dc577..7daf345c5ee7f1a8e28b024895afbb7b37e57a09 100644 (file)
@@ -113,7 +113,7 @@ void dumpTeddyDupMasks(const u8 *dmsk, u32 numMasks, FILE *f) {
     u32 maskWidth = 2;
     fprintf(f, "    dup nibble masks:\n");
     for (u32 i = 0; i < numMasks * 2; i++) {
-        fprintf(f, "      -%d%s: ", 1 + i / 2, (i % 2) ? "hi" : "lo");
+        fprintf(f, "      -%u%s: ", 1 + i / 2, (i % 2) ? "hi" : "lo");
         for (u32 j = 0; j < 16 * maskWidth * 2; j++) {
             u8 val = dmsk[i * 16 * maskWidth * 2 + j];
             for (u32 k = 0; k < 8; k++) {
@@ -131,7 +131,7 @@ void dumpTeddyMasks(const u8 *baseMsk, u32 numMasks, u32 maskWidth, FILE *f) {
     // dump nibble masks
     fprintf(f, "    nibble masks:\n");
     for (u32 i = 0; i < numMasks * 2; i++) {
-        fprintf(f, "      -%d%s: ", 1 + i / 2, (i % 2) ? "hi" : "lo");
+        fprintf(f, "      -%u%s: ", 1 + i / 2, (i % 2) ? "hi" : "lo");
         for (u32 j = 0; j < 16 * maskWidth; j++) {
             u8 val = baseMsk[i * 16 * maskWidth + j];
             for (u32 k = 0; k < 8; k++) {
index bb83849b69450390edee3490d3b034a6f9694195..e381fc4796232c4e1a03398ac506b46f1dba5c14 100644 (file)
@@ -93,6 +93,7 @@ void dumpLits(UNUSED const vector<hwlmLiteral> &lits) {
 // Called by an assertion.
 static
 bool everyoneHasGroups(const vector<hwlmLiteral> &lits) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &lit : lits) {
         if (!lit.groups) {
             return false;
index 4765cd03751d3ca9dcf5f96ec53d1d22e954766b..322b87ab9c0917cb25246d34c142d224b4e7319d 100644 (file)
@@ -595,6 +595,7 @@ void GoughSSAVarNew::generate(vector<gough_ins> *out) const {
 #ifndef NDEBUG
 template<typename C, typename K>
 bool contains_loose(const C &container, const K &key) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &elem : container) {
         if (elem == key) {
             return true;
@@ -986,7 +987,6 @@ void copy_in_blocks(raw_som_dfa &raw, u8 alphaShift, const GoughGraph &cfg,
 }
 
 bool find_normal_self_loop(GoughVertex v, const GoughGraph &g, GoughEdge *out) {
-    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : out_edges_range(v, g)) {
         if (target(e, g) != v) {
             continue;
index ca94b69f3ac228fd9dcee4b20a8894cb0eb5a553..649310c6e9949ec0f41249b3c6e5505d06dc4375 100644 (file)
@@ -145,6 +145,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base,
             fprintf(f, "\tuses:");
             vector<u32> used_id;
             for (const GoughSSAVar *var : used) {
+                // cppcheck-suppress useStlAlgorithm
                 used_id.emplace_back(var->slot);
             }
             for (const u32 &id : used_id) {
@@ -167,6 +168,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base,
             fprintf(f, "\tuses:");
             vector<u32> used_id;
             for (const GoughSSAVar *var : used) {
+                // cppcheck-suppress useStlAlgorithm
                 used_id.emplace_back(var->slot);
             }
             for (const u32 &id : used_id) {
index 92131306a96e9a000d6749a086b286e7b30f273d..6668ddbddebfe73a873e3d88f77c29073aa96898 100644 (file)
@@ -50,8 +50,8 @@ namespace ue2 {
 
 template<typename VarP, typename VarQ>
 void emplace_back_all_raw(vector<VarP> *out, const vector<VarQ> &in) {
-    // cppcheck-suppress useStlAlgorithm
     for (const auto &var : in) {
+        // cppcheck-suppress useStlAlgorithm
         out->emplace_back(var.get());
     }
 }
index 8717d06a009ce5662b1dde76d4cbf39a08c9154d..ee2e873d5f7b18e46c9f8205c249221523d6d5f6 100644 (file)
@@ -336,7 +336,7 @@ void nfaExecGough16_dumpText(const struct NFA *nfa, FILE *f) {
             m->state_count, m->length);
     fprintf(f, "astart: %hu, fstart: %hu\n", m->start_anchored,
             m->start_floating);
-    fprintf(f, "single accept: %d\n", !!(int)m->flags & MCCLELLAN_FLAG_SINGLE);
+    fprintf(f, "single accept: %d\n", !!(m->flags & MCCLELLAN_FLAG_SINGLE));
     fprintf(f, "sherman_limit: %u, sherman_end: %u\n", m->sherman_limit,
             m->sherman_end);
 
index 5ae35431e43d9b0e9847f46c7a5d5a0d11fe2569..4f530e6decfe8af914b17ada5e0ab17a8967e094 100644 (file)
@@ -279,6 +279,7 @@ char JOIN(ENGINE_EXEC_NAME, _Q_i)(const struct NFA *nfa, struct mq *q,
                 assert(rv == MO_CONTINUE_MATCHING);
             }
 
+            // cppcheck-suppress knownConditionTrueFalse
             if (escape_found) {
                 DEBUG_PRINTF("clearing repeat due to escape\n");
                 clearRepeat(info, lstate);
@@ -355,6 +356,7 @@ void JOIN(ENGINE_EXEC_NAME, _StreamSilent)(const struct NFA *nfa, struct mq *q,
 
     size_t eloc = 0;
     char escaped = FWDSCAN_FN(nfa, buf, 0, length, &eloc);
+    // cppcheck-suppress knownConditionTrueFalse
     if (escaped) {
         assert(eloc < length);
         DEBUG_PRINTF("escape found at %zu, clearing repeat\n", eloc);
index 48661871746f6464c7fabd62841ca9fcd1805be5..2b0b36993287dd93bf4054a5ae16a410d685eede 100644 (file)
@@ -125,6 +125,7 @@ char PROCESS_ACCEPTS_IMPL_FN(const IMPL_NFA_T *limex, const STATE_T *s,
     const STATE_T accept_mask = *acceptMask;
     STATE_T accepts = AND_STATE(*s, accept_mask);
 
+    DEBUG_PRINTF("sizeof(STATE_T): %ld, sizeof(CHUNK_T): %ld, NUM_STATE_CHUNKS: %ld\n", sizeof(STATE_T), sizeof(CHUNK_T), NUM_STATE_CHUNKS);
     // Caller must ensure that we have at least one accept state on.
     assert(ISNONZERO_STATE(accepts));
 
@@ -135,6 +136,7 @@ char PROCESS_ACCEPTS_IMPL_FN(const IMPL_NFA_T *limex, const STATE_T *s,
     memcpy(mask_chunks, &accept_mask, sizeof(accept_mask));
 
     u32 base_index = 0; // Cumulative sum of mask popcount up to current chunk.
+    // cppcheck-suppress unsignedLessThanZero
     for (u32 i = 0; i < NUM_STATE_CHUNKS; i++) {
         CHUNK_T chunk = chunks[i];
         while (chunk != 0) {
@@ -358,6 +360,7 @@ char LIMEX_INACCEPT_FN(const IMPL_NFA_T *limex, STATE_T state,
     memcpy(mask_chunks, &accept_mask, sizeof(accept_mask));
 
     u32 base_index = 0; // Cumulative sum of mask popcount up to current chunk.
+    // cppcheck-suppress unsignedLessThanZero
     for (u32 i = 0; i < NUM_STATE_CHUNKS; i++) {
         CHUNK_T chunk = chunks[i];
         while (chunk != 0) {
index 5b32e9102bf5f1041ba64a01ffffe4dd7937f92f..304116a80c52d69c1b3dc04a2de950e0a00ad195 100644 (file)
@@ -140,6 +140,7 @@ reindexByStateId(const unordered_map<NFAVertex, NFAStateSet> &in,
         for (size_t i = m.second.find_first(); i != m.second.npos;
              i = m.second.find_next(i)) {
             u32 state_id = indexToState[i];
+           // cppcheck-suppress knownConditionTrueFalse
             if (state_id == NO_STATE) {
                 continue;
             }
@@ -586,6 +587,7 @@ bool containsBadSubset(const limex_accel_info &accel,
         subset = state_set;
         subset.reset(j);
 
+        // cppcheck-suppress knownConditionTrueFalse
         if (effective_sds != NO_STATE && subset.count() == 1 &&
             subset.test(effective_sds)) {
             continue;
@@ -1088,6 +1090,7 @@ void buildAccepts(const build_info &args, ReportListCache &reports_cache,
     for (auto v : vertices_range(h)) {
         u32 state_id = args.state_ids.at(v);
 
+        // cppcheck-suppress knownConditionTrueFalse
         if (state_id == NO_STATE || !is_match_vertex(v, h)) {
             continue;
         }
@@ -1147,6 +1150,7 @@ u32 compressedStateSize(const NGHolder &h, const NFAStateSet &maskedStates,
 
     for (auto v : vertices_range(h)) {
         u32 i = state_ids.at(v);
+        // cppcheck-suppress knownConditionTrueFalse
         if (i == NO_STATE || maskedStates.test(i)) {
             continue;
         }
@@ -1172,6 +1176,7 @@ bool hasSquashableInitDs(const build_info &args) {
 
     NFAStateSet initDs(args.num_states);
     u32 sds_state = args.state_ids.at(h.startDs);
+    // cppcheck-suppress knownConditionTrueFalse
     if (sds_state == NO_STATE) {
         DEBUG_PRINTF("no states in initds\n");
         return false;
@@ -1232,6 +1237,7 @@ void findMaskedCompressionStates(const build_info &args,
         // Rose leftfixes can mask out initds, which is worth doing if it will
         // stay on forever (i.e. it's not squashable).
         u32 sds_i = args.state_ids.at(h.startDs);
+        // cppcheck-suppress knownConditionTrueFalse
         if (sds_i != NO_STATE && !hasSquashableInitDs(args)) {
             maskedStates.set(sds_i);
             DEBUG_PRINTF("masking out initds state\n");
@@ -1247,6 +1253,7 @@ void findMaskedCompressionStates(const build_info &args,
         for (const auto &e : edges_range(h)) {
             u32 from = args.state_ids.at(source(e, h));
             u32 to = args.state_ids.at(target(e, h));
+            // cppcheck-suppress knownConditionTrueFalse
             if (from == NO_STATE) {
                 continue;
             }
@@ -1254,6 +1261,7 @@ void findMaskedCompressionStates(const build_info &args,
             // We cannot mask out EOD accepts, as they have to perform an
             // action after they're switched on that may be delayed until the
             // next stream write.
+            // cppcheck-suppress knownConditionTrueFalse
             if (to == NO_STATE && target(e, h) != h.acceptEod) {
                 continue;
             }
@@ -1404,6 +1412,7 @@ u32 buildExceptionMap(const build_info &args, ReportListCache &reports_cache,
     for (auto v : vertices_range(h)) {
         const u32 i = args.state_ids.at(v);
 
+        // cppcheck-suppress knownConditionTrueFalse
         if (i == NO_STATE) {
             continue;
         }
@@ -1487,6 +1496,7 @@ u32 buildExceptionMap(const build_info &args, ReportListCache &reports_cache,
                 }
                 u32 j = args.state_ids.at(w);
                 // j can be NO_STATE if args.state_ids.at(w) returns NO_STATE
+                // cppcheck-suppress knownConditionTrueFalse
                 if (j == NO_STATE) {
                     continue;
                 }
@@ -1559,6 +1569,7 @@ u32 findMaxVarShift(const build_info &args, u32 nShifts) {
     for (const auto &e : edges_range(h)) {
         u32 from = args.state_ids.at(source(e, h));
         u32 to = args.state_ids.at(target(e, h));
+        // cppcheck-suppress knownConditionTrueFalse
         if (from == NO_STATE || to == NO_STATE) {
             continue;
         }
@@ -1588,6 +1599,7 @@ int getLimexScore(const build_info &args, u32 nShifts) {
     for (const auto &e : edges_range(h)) {
         u32 from = args.state_ids.at(source(e, h));
         u32 to = args.state_ids.at(target(e, h));
+        // cppcheck-suppress knownConditionTrueFalse
         if (from == NO_STATE || to == NO_STATE) {
             continue;
         }
@@ -1836,6 +1848,7 @@ struct Factory {
         u32 s_i = args.state_ids.at(h.start);
         u32 sds_i = args.state_ids.at(h.startDs);
 
+        // cppcheck-suppress knownConditionTrueFalse
         if (s_i != NO_STATE) {
             maskSetBit(limex->init, s_i);
             if (is_triggered(h)) {
@@ -1843,6 +1856,7 @@ struct Factory {
             }
         }
 
+        // cppcheck-suppress knownConditionTrueFalse
         if (sds_i != NO_STATE) {
             maskSetBit(limex->init, sds_i);
             maskSetBit(limex->initDS, sds_i);
@@ -1878,6 +1892,7 @@ struct Factory {
         for (const auto &e : edges_range(h)) {
             u32 from = args.state_ids.at(source(e, h));
             u32 to = args.state_ids.at(target(e, h));
+            // cppcheck-suppress knownConditionTrueFalse
             if (from == NO_STATE || to == NO_STATE) {
                 continue;
             }
@@ -1916,6 +1931,7 @@ struct Factory {
         for (const auto &e : edges_range(h)) {
             u32 from = args.state_ids.at(source(e, h));
             u32 to = args.state_ids.at(target(e, h));
+            // cppcheck-suppress knownConditionTrueFalse
             if (from == NO_STATE || to == NO_STATE) {
                 continue;
             }
@@ -2458,6 +2474,7 @@ bool isSane(const NGHolder &h, const map<u32, set<NFAVertex>> &tops,
             return false;
         }
         const u32 i = state_ids.at(v);
+        // cppcheck-suppress knownConditionTrueFalse
         if (i == NO_STATE) {
             continue;
         }
@@ -2538,6 +2555,7 @@ bool isFast(const build_info &args) {
                     continue;
                 }
                 u32 j = args.state_ids.at(w);
+                // cppcheck-suppress knownConditionTrueFalse
                 if (j == NO_STATE) {
                     continue;
                 }
index f472aee41c359a0e728437cd61f5ff2fb0fb92eb..2488787c6823d776dc9475cbe8df80483b2ae46b 100644 (file)
@@ -322,6 +322,7 @@ int PE_FN(STATE_ARG, ESTATE_ARG, UNUSED u32 diffmask, STATE_T *succ,
 #ifdef ARCH_64_BIT
         t >>= 1; // Due to diffmask64, which leaves holes in the bitmask.
 #endif
+       // cppcheck-suppress unsignedLessThanZero
         assert(t < ARRAY_LENGTH(chunks));
         CHUNK_T word = chunks[t];
         assert(word != 0);
index 44831b3d524e1d4db2330dc05427df23683926bc..59ec005cd1293047d2bfc5680858d4e37c09ab15 100644 (file)
@@ -210,6 +210,7 @@ set<ReportID> all_reports(const raw_dfa &rdfa) {
 }
 
 bool has_eod_accepts(const raw_dfa &rdfa) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &ds : rdfa.states) {
         if (!ds.reports_eod.empty()) {
             return true;
@@ -219,6 +220,7 @@ bool has_eod_accepts(const raw_dfa &rdfa) {
 }
 
 bool has_non_eod_accepts(const raw_dfa &rdfa) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &ds : rdfa.states) {
         if (!ds.reports.empty()) {
             return true;
index 071dd85b042ffb31e3af9b8c365c4370df6d42d6..475d3ebaf50f91d9a2ddbc1897bbfa8773d655c7 100644 (file)
@@ -360,7 +360,7 @@ void dumpCommonHeader(FILE *f, const mcclellan *m) {
     fprintf(f, "astart: %hu, fstart: %hu\n", m->start_anchored,
             m->start_floating);
     fprintf(f, "single accept: %d, has_accel: %d\n",
-            !!(int)m->flags & MCCLELLAN_FLAG_SINGLE, m->has_accel);
+            !!(m->flags & MCCLELLAN_FLAG_SINGLE), m->has_accel);
 }
 
 static
index 352a90058bafee1c213314dcd7b1a8586ce518e7..4a2a2129124188cf1be2bef79f8c31122ac94d6d 100644 (file)
@@ -530,7 +530,7 @@ void dumpCommonHeader(FILE *f, const mcsheng *m) {
     fprintf(f, "astart: %hu, fstart: %hu\n", m->start_anchored,
             m->start_floating);
     fprintf(f, "single accept: %d, has_accel: %d\n",
-            !!(int)m->flags & MCSHENG_FLAG_SINGLE, m->has_accel);
+            !!(m->flags & MCSHENG_FLAG_SINGLE), m->has_accel);
     fprintf(f, "sheng_end:         %hu\n", m->sheng_end);
     fprintf(f, "sheng_accel_limit: %hu\n", m->sheng_accel_limit);
 }
@@ -655,7 +655,7 @@ void dumpCommonHeader64(FILE *f, const mcsheng64 *m) {
     fprintf(f, "astart: %hu, fstart: %hu\n", m->start_anchored,
             m->start_floating);
     fprintf(f, "single accept: %d, has_accel: %d\n",
-            !!(int)m->flags & MCSHENG_FLAG_SINGLE, m->has_accel);
+            !!(m->flags & MCSHENG_FLAG_SINGLE), m->has_accel);
     fprintf(f, "sheng_end:         %hu\n", m->sheng_end);
     fprintf(f, "sheng_accel_limit: %hu\n", m->sheng_accel_limit);
 }
index 7c06da9d7e4ca29416176f79486e41d56cdf33bb..7071b6ce42a99a98aed2333834618be0a60314c2 100644 (file)
@@ -105,6 +105,7 @@ void writeSentinel(mpv_puffette *out) {
 static
 void writeDeadPoint(mpv_kilopuff *out, const vector<raw_puff> &puffs) {
     for (const auto &puff : puffs) {
+        // cppcheck-suppress useStlAlgorithm
         if (puff.unbounded) { /* mpv can never die */
             out->dead_point = MPV_DEAD_VALUE;
             return;
@@ -313,6 +314,7 @@ static
 const mpv_counter_info &findCounter(const vector<mpv_counter_info> &counters,
                                     u32 i) {
     for (const auto &counter : counters) {
+        // cppcheck-suppress useStlAlgorithm
         if (i >= counter.kilo_begin && i < counter.kilo_end) {
             return counter;
         }
index 86eb15100ceb38c110a6ac462fa167aa5c5ea8ce..eed33c970a960a73dd7f0fd0434a056878dc8b16 100644 (file)
@@ -138,7 +138,7 @@ template<NFAEngineType t>
 static
 string getDescriptionLimEx(const NFA *nfa) {
     const typename NFATraits<t>::implNFA_t *limex =
-        (const typename NFATraits<t>::implNFA_t *)getImplNfa(nfa);
+        reinterpret_cast<const typename NFATraits<t>::implNFA_t *>(getImplNfa(nfa));
     ostringstream oss;
     oss << NFATraits<t>::name << "/" << limex->exceptionCount;
     if (limex->repeatCount) {
index 474db9b8ec605f08394188faa0e6a626457b4f89..4ce2a79773539a09479d9834dba98ec6cd3a3468 100644 (file)
@@ -137,13 +137,13 @@ void dumpTextReverse(const struct NFA *nfa, FILE *f) {
     char c2 = nfa->rAccelData.array[1];
 
     if (!twofer) {
-        fprintf(f, " \\x%02hhx (%c) ", c1, isprint(c1) ? c1 : '?');
+        fprintf(f, " \\x%02hhx (%c) ", static_cast<u8>(c1), isprint(c1) ? c1 : '?');
     } else {
-        fprintf(f, " \\x%02hhx\\x%02hhx (%c%c) ", c1, c2,
+        fprintf(f, " \\x%02hhx\\x%02hhx (%c%c) ", static_cast<u8>(c1), static_cast<u8>(c2),
                 isprint(c1) ? c1 : '?', isprint(c2) ? c2 : '?');
     }
 
-    fprintf(f, "offset %hhd\n", nfa->rAccelOffset);
+    fprintf(f, "offset %hhu\n", nfa->rAccelOffset);
 }
 
 } // namespace ue2
index ae857b6af2333cb1a8e72f2564004308efc06229..278816d0b9949a84508b701b57b806a5a3dfd57c 100644 (file)
@@ -44,6 +44,7 @@ void raw_dfa::stripExtraEodReports(void) {
 }
 
 bool raw_dfa::hasEodReports(void) const {
+    // cppcheck-suppress useStlAlgorithm
     for (const dstate &ds : states) {
         if (!ds.reports_eod.empty()) {
             return true;
index 6b994e4f2f3ae82fdc830aa1a479aac1ee9a148a..01910c2808387f134f1ec753bb4694786241fcf1 100644 (file)
@@ -76,7 +76,7 @@ struct raw_dfa {
     u16 alpha_size = 0; /* including special symbols */
 
     /* mapping from input symbol --> equiv class id */
-    std::array<u16, ALPHABET_SIZE> alpha_remap;
+    std::array<u16, ALPHABET_SIZE> alpha_remap{};
 
     explicit raw_dfa(nfa_kind k) : kind(k) {}
     virtual ~raw_dfa();
index 588f94e388578f4f453b15d00af9bcee18b8d464..b06521150163c110fdd6d51353558fd21023d590 100644 (file)
@@ -232,6 +232,7 @@ public:
 
         // Must all be external reports.
         assert(rm);
+        // cppcheck-suppress useStlAlgorithm
         for (const auto &report_id : test_reports) {
             if (!isExternalReport(rm->getReport(report_id))) {
                 return false;
@@ -247,6 +248,7 @@ public:
         flat_set<ReportID> seen_reports;
         for (const auto &rdfa : nfas) {
             for (const auto &report_id : all_reports(*rdfa)) {
+                // cppcheck-suppress useStlAlgorithm
                 if (!seen_reports.insert(report_id).second) {
                     DEBUG_PRINTF("report %u in several dfas\n", report_id);
                     return true;
index c0c4a56fa7d729cd8a0611e580fd68978de60bcf..2c350bb08f41ca843e898a6efeafb7e75b02be24 100644 (file)
@@ -101,7 +101,7 @@ void dumpHeader(FILE *f, const sheng *s) {
     fprintf(f, "aux base offset: %u, reports base offset: %u, "
                "accel offset: %u\n",
             s->aux_offset, s->report_offset, s->accel_offset);
-    fprintf(f, "anchored start state: %u, floating start state: %u\n",
+    fprintf(f, "anchored start state: %d, floating start state: %d\n",
             s->anchored & SHENG_STATE_MASK, s->floating & SHENG_STATE_MASK);
     fprintf(f, "has accel: %u can die: %u single report: %u\n",
             !!(s->flags & SHENG_FLAG_HAS_ACCEL),
@@ -116,7 +116,7 @@ void dumpHeader32(FILE *f, const sheng32 *s) {
     fprintf(f, "aux base offset: %u, reports base offset: %u, "
                "accel offset: %u\n",
             s->aux_offset, s->report_offset, s->accel_offset);
-    fprintf(f, "anchored start state: %u, floating start state: %u\n",
+    fprintf(f, "anchored start state: %d, floating start state: %d\n",
             s->anchored & SHENG32_STATE_MASK, s->floating & SHENG32_STATE_MASK);
     fprintf(f, "has accel: %u can die: %u single report: %u\n",
             !!(s->flags & SHENG_FLAG_HAS_ACCEL),
@@ -131,7 +131,7 @@ void dumpHeader64(FILE *f, const sheng64 *s) {
     fprintf(f, "aux base offset: %u, reports base offset: %u, "
                "accel offset: %u\n",
             s->aux_offset, s->report_offset, s->accel_offset);
-    fprintf(f, "anchored start state: %u, floating start state: %u\n",
+    fprintf(f, "anchored start state: %d, floating start state: %d\n",
             s->anchored & SHENG64_STATE_MASK, s->floating & SHENG64_STATE_MASK);
     fprintf(f, "has accel: %u can die: %u single report: %u\n",
             !!(s->flags & SHENG_FLAG_HAS_ACCEL),
@@ -182,9 +182,9 @@ void dumpMasks(FILE *f, const sheng *s) {
         for (u32 pos = 0; pos < 16; pos++) {
             u8 c = buf[pos];
             if (c & SHENG_STATE_FLAG_MASK) {
-                fprintf(f, "%2u* ", c & SHENG_STATE_MASK);
+                fprintf(f, "%2d* ", c & SHENG_STATE_MASK);
             } else {
-                fprintf(f, "%2u  ", c & SHENG_STATE_MASK);
+                fprintf(f, "%2d  ", c & SHENG_STATE_MASK);
             }
         }
         fprintf(f, "\n");
@@ -202,9 +202,9 @@ void dumpMasks32(FILE *f, const sheng32 *s) {
         for (u32 pos = 0; pos < 64; pos++) {
             u8 c = buf[pos];
             if (c & SHENG32_STATE_FLAG_MASK) {
-                fprintf(f, "%2u* ", c & SHENG32_STATE_MASK);
+                fprintf(f, "%2d* ", c & SHENG32_STATE_MASK);
             } else {
-                fprintf(f, "%2u  ", c & SHENG32_STATE_MASK);
+                fprintf(f, "%2d  ", c & SHENG32_STATE_MASK);
             }
         }
         fprintf(f, "\n");
@@ -222,9 +222,9 @@ void dumpMasks64(FILE *f, const sheng64 *s) {
         for (u32 pos = 0; pos < 64; pos++) {
             u8 c = buf[pos];
             if (c & SHENG64_STATE_FLAG_MASK) {
-                fprintf(f, "%2u* ", c & SHENG64_STATE_MASK);
+                fprintf(f, "%2d* ", c & SHENG64_STATE_MASK);
             } else {
-                fprintf(f, "%2u  ", c & SHENG64_STATE_MASK);
+                fprintf(f, "%2d  ", c & SHENG64_STATE_MASK);
             }
         }
         fprintf(f, "\n");
@@ -358,7 +358,7 @@ void dumpDotPreambleDfa(FILE *f) {
 template <typename T>
 static
 void describeNode(UNUSED const NFA *n, UNUSED const T *s, UNUSED u16 i,
-                  UNUSED FILE *f) {
+                  UNUSED FILE *f) { // cppcheck-suppress constParameterPointer
 }
 
 template <>
index 43480f06506130395a5ecdacb14b624e2dc2d598..cfb78c7e5edd7f4b3df348b22148cf24921f17cd 100644 (file)
@@ -299,7 +299,7 @@ char nfaExecTamarama_QR(const struct NFA *n, struct mq *q, ReportID report) {
         rv = nfaQueueExecRose(q1.nfa, &q1, report);
     }
 
-    DEBUG_PRINTF("exec rose rv:%u\n", rv);
+    DEBUG_PRINTF("exec rose rv:%d\n", rv);
     return rv;
 }
 
index 5ca4160494a03a7b3e48a361b8dc197bdf430501..7dc3ebba3059f8afc182f3685e4fe258675a05ba 100644 (file)
@@ -131,7 +131,7 @@ buildTamarama(const TamaInfo &tamaInfo, const u32 queue,
         sizeof(u32) * subSize + 64; // offsets to subengines in bytecode and
                                     // padding for subengines
 
-    auto subl = [](size_t z, NFA *sub) {
+    auto subl = [](size_t z, const NFA *sub) {
         return z + (size_t)(ROUNDUP_CL(sub->length));
     };
     total_size += std::accumulate(tamaInfo.subengines.begin(), tamaInfo.subengines.end(), 0, subl);
index 5b9e5a49c8ae46278558ec6e9cc776b908714fce..923163bd7bec4db2142ea5cef5eb4a64065ca062 100644 (file)
@@ -220,6 +220,7 @@ bool inIsIrreducible(const NFAVertex &v, const NGHolder &g) {
  * just a chain of vertices with no other edges. */
 static
 bool isIrreducible(const NGHolder &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (auto v : vertices_range(g)) {
         // skip specials
         if (is_special(v, g)) {
@@ -244,11 +245,13 @@ bool isIrreducible(const NGHolder &g) {
 #ifndef NDEBUG
 static
 bool hasEdgeAsserts(NFAVertex v, const NGHolder &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : in_edges_range(v, g)) {
         if (g[e].assert_flags != 0) {
             return true;
         }
     }
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : out_edges_range(v, g)) {
         if (g[e].assert_flags != 0) {
             return true;
index 36cf62447b89a70a611b22e1d8c16d42035a9b56..b2d36bccc263ebe12e11227ef0706b68a57a7eeb 100644 (file)
@@ -114,6 +114,7 @@ public:
 
     nfa_kind kind; /* Role that this plays in Rose */
 
+    // cppcheck-suppress duplInheritedMember
     static const size_t N_SPECIAL_VERTICES = N_SPECIALS;
 public:
     const vertex_descriptor start;     //!< Anchored start vertex.
index dad3cb47712c76eeef619f9ba489ecf3cd3eecad..e7c28b18ac4ff4132e4a35e17ec0a4f54c1b0688 100644 (file)
@@ -106,6 +106,7 @@ bool sanityCheckGraph(const NGHolder &g,
             return false;
         }
         u32 s = state_ids.at(v);
+        // cppcheck-suppress knownConditionTrueFalse
         if (s != NO_STATE && !seen_states.insert(s).second) {
             DEBUG_PRINTF("vertex %zu has dupe state %u\n", g[v].index, s);
             return false;
@@ -392,8 +393,8 @@ void reusePredsAsStarts(const NGHolder &g, const map<u32, CharReach> &top_reach,
     auto cands = [&g=g](const NFAVertex &u) {
         return (hasSelfLoop(u, g));
     };
-    const auto &u = unhandled_succ_tops | map_keys;
-    std::copy_if(begin(u), end(u),  std::back_inserter(cand_starts), cands);
+    const auto &ust = unhandled_succ_tops | map_keys;
+    std::copy_if(begin(ust), end(ust),  std::back_inserter(cand_starts), cands);
 
     for (NFAVertex u : cand_starts) {
         if (!contains(unhandled_succ_tops, u)) {
index 0cf6006d61a042b2faf0e0cae609c6126b00c41b..21e7fa0588fc4465e65439f7960d9087f1aed9a8 100644 (file)
@@ -463,6 +463,7 @@ void blowoutPathsLessStrictSegment(vector<vector<CharReach> > &paths) {
     /* paths segments which are a superset of an earlier segment should never be
      * picked as an acceleration segment -> to improve processing just replace
      * with dot */
+    // cppcheck-suppress constVariableReference
     for (auto &p : paths) {
         for (auto it = p.begin(); it != p.end();  ++it) {
             for (auto jt = next(it); jt != p.end(); ++jt) {
index bd9c3ab22468416437b58e8b1d8e0d2cde3808b3..178f5aa35d8680559fa63dda02f9f75207eaacef 100644 (file)
@@ -360,8 +360,8 @@ u64a litUniqueness(const string &s) {
 static
 u64a litCountBits(const ue2_literal &lit) {
     u64a n = 0;
-    // cppcheck-suppress useStlAlgorithm
     for (const auto &c : lit) {
+        // cppcheck-suppress useStlAlgorithm
         n += c.nocase ? 7 : 8;
     }
     return n;
@@ -491,8 +491,8 @@ vector<LitEdge> add_reverse_edges_and_index(LitGraph &lg) {
     vector<LitEdge> fwd_edges;
     fwd_edges.reserve(edge_count);
 
-    const auto &e = edges_range(lg);
-    std::copy(begin(e), end(e),  std::back_inserter(fwd_edges));
+    const auto &er = edges_range(lg);
+    std::copy(begin(er), end(er),  std::back_inserter(fwd_edges));
 
     vector<LitEdge> rev_map(2 * edge_count);
 
@@ -881,6 +881,7 @@ bool literalIsWholeGraph(const NGHolder &g, const ue2_literal &lit) {
     }
 
     // Our last value for v should have only start states for predecessors.
+    // cppcheck-suppress useStlAlgorithm
     for (auto u : inv_adjacent_vertices_range(v, g)) {
         if (!is_any_start(u, g)) {
             DEBUG_PRINTF("pred is not start\n");
index 7fa2416a1fa560784dfbc045acb9a70416050c04..85fbc0819f94197a42aa0472ae62f15207d30d97 100644 (file)
@@ -131,6 +131,7 @@ bool findPaths(const NGHolder &g, vector<Path> &paths) {
 
 static
 bool hasLargeDegreeVertex(const NGHolder &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &v : vertices_range(g)) {
         if (is_special(v, g)) { // specials can have large degree
             continue;
index 1e4b743f7c63e7cef53fd24d1d97b9192a82eb54..3b6c076001078539f295ed073c457ffc9d81766c 100644 (file)
@@ -129,6 +129,7 @@ void calculateAlphabet(const NGHolder &g, array<u16, ALPHABET_SIZE> &alpha,
 static
 bool allExternalReports(const ReportManager &rm,
                         const flat_set<ReportID> &reports) {
+    // cppcheck-suppress useStlAlgorithm
     for (auto report_id : reports) {
         if (!isExternalReport(rm.getReport(report_id))) {
             return false;
@@ -327,6 +328,7 @@ void markToppableStarts(const NGHolder &g, const flat_set<NFAVertex> &unused,
             continue;
         }
         for (const auto &trigger : triggers) {
+            // cppcheck-suppress useStlAlgorithm
             if (triggerAllowed(g, v, triggers, trigger)) {
                 DEBUG_PRINTF("idx %zu is valid location for top\n", g[v].index);
                 out->set(g[v].index);
index fa7496c53e39ac8cfd032287023cdf97b17f7cc5..1eb84233d613d4c3bb661aa03f3ef2c852d458f4 100644 (file)
@@ -482,6 +482,7 @@ vector<CharReach> reduced_cr(const NGHolder &g,
 
 static
 bool anyOutSpecial(NFAVertex v, const NGHolder &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (auto w : adjacent_vertices_range(v, g)) {
         if (is_special(w, g) && w != v) {
             return true;
index 9f53a0e46510f6b0068524c5091f94911ca074c6..e19c94bad56de011888d5261a2c4b35ca2f7e4cb 100644 (file)
@@ -115,6 +115,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v,
                    const std::unordered_map<NFAVertex, u32> &region_map) {
     // Note that some graph types do not have inv_adjacent_vertices, so we must
     // use in_edges here.
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : in_edges_range(v, g)) {
         if (!inSameRegion(g, v, source(e, g), region_map)) {
             return true;
@@ -128,6 +129,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v,
 template <class Graph>
 bool isRegionExit(const Graph &g, NFAVertex v,
                   const std::unordered_map<NFAVertex, u32> &region_map) {
+    // cppcheck-suppress useStlAlgorithm
     for (auto w : adjacent_vertices_range(v, g)) {
         if (!inSameRegion(g, v, w, region_map)) {
             return true;
index 4c5341c8f5ac2b363e23368d4d63b62994be01d9..b94e22a1988f573d6a838d6dd5f44230a49e2ed9 100644 (file)
@@ -2181,6 +2181,7 @@ bool hasOverlappingRepeats(UNUSED const NGHolder &g,
             DEBUG_PRINTF("already seen pos %zu\n", g[br.pos_trigger].index);
             return true;
         }
+        // cppcheck-suppress useStlAlgorithm
         for (auto v : br.tug_triggers) {
             if (contains(involved, v)) {
                 DEBUG_PRINTF("already seen tug %zu\n", g[v].index);
index 99f287db26561839cd12aa205103d905fbe86990..a05f0f63c7ea5c75eeb29f3dcefa8e023f5faf0f 100644 (file)
@@ -210,7 +210,6 @@ u32 countStates(const unordered_map<NFAVertex, u32> &state_ids) {
     u32 max_state = 0;
     for (const auto &m : state_ids) {
         if (m.second != NO_STATE) {
-            // cppcheck-suppress useStlAlgorithm
             max_state = max(m.second, max_state);
         }
     }
index 605f669ca12ae2d273b4a556487a946a77956083..90b49929730bf19189a01ad6020b52c460c823dd 100644 (file)
@@ -776,12 +776,14 @@ bool allMatchStatesHaveReports(const NGHolder &g) {
 
 bool isCorrectlyTopped(const NGHolder &g) {
     if (is_triggered(g)) {
+        // cppcheck-suppress useStlAlgorithm
         for (const auto &e : out_edges_range(g.start, g)) {
             if (g[e].tops.empty() != (target(e, g) == g.startDs)) {
                 return false;
             }
         }
     } else {
+        // cppcheck-suppress useStlAlgorithm
         for (const auto &e : out_edges_range(g.start, g)) {
             if (!g[e].tops.empty()) {
                 return false;
index 232b02188022c89f2499076f37b2f547c565f1fc..2ab9483aaca2dd3bfb4d89da6584d121ac56d8ee 100644 (file)
@@ -164,7 +164,7 @@ ComponentSequence *enterSequence(ComponentSequence *parent,
 
     ComponentSequence *seq = child.get();
     parent->addComponent(std::move(child));
-    return seq;
+    return seq; // cppcheck-suppress returnDanglingLifetime
 }
 
 static
index c243f62670547907551cb5321ee31d4338201560..871f1180bb9a92f59857551ca9d01d67a4ebe7c9 100644 (file)
@@ -99,7 +99,8 @@ public:
     const NFABuilder &getBuilder() const override { return builder; }
 
     /** \brief Wire up the lasts of one component to the firsts of another. */
-    void connectRegions(const vector<PositionInfo> &lasts,
+    // cppcheck-suppress virtualCallInConstructor
+    virtual void connectRegions(const vector<PositionInfo> &lasts,
                         const vector<PositionInfo> &firsts) override;
 
     /** \brief Wire the lasts of the main sequence to accepts. */
index 09b0bfd7bc92884fd8ca484360816ad12b34b07b..ca682da6a473915b9262e552a1392acb42b69527 100644 (file)
@@ -108,6 +108,8 @@ const char *read_control_verbs(const char *ptr, const char *end, size_t start,
     try {
         %% write exec;
     } catch (LocatedParseError &error) {
+        // cppcheck-suppress pointerLessThanZero
+        // cppcheck-suppress pointerPositive
         if (ts >= ptr && ts <= pe) {
             error.locate(ts - ptr + start);
         } else {
index 4e64a2802925f1a413ee1f14b3b85dc72eb521a8..e9a03870bbb98d606742cd346021caeeb4f9f18a 100644 (file)
@@ -37,6 +37,7 @@ namespace ue2 {
 /** Class representing a component state. */
 class PositionInfo {
 public:
+    // cppcheck-suppress noExplicitConstructor
     PositionInfo(unsigned int p) : pos(p), flags(0) {}
 
     bool operator<(const PositionInfo &other) const {
index f69362e4e330557a97d652afdea32abc4f5a243f..3836a6fe7d103839351a08220ced0dfe8e77f14b 100644 (file)
@@ -347,6 +347,7 @@ void prefilterTree(unique_ptr<Component> &root, const ParseMode &mode) {
     assert(root);
     PrefilterVisitor vis(root.get(), mode);
 
+    // cppcheck-suppress constVariablePointer
     Component *c = root->accept(vis);
     if (c != root.get()) {
         root.reset(c);
index 78d13e3c09afb72fbff5e4729a4ae48097ef4141..9eafc80daa00a60e11049ed95d7533c6283dacf7 100644 (file)
@@ -1496,6 +1496,7 @@ void transformSuffixDelay(RoseInGraph &ig, const CompileContext &cc) {
 #ifndef NDEBUG
 static
 bool validateKinds(const RoseInGraph &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : edges_range(g)) {
         if (g[e].graph && g[e].graph->kind != whatRoseIsThis(g, e)) {
             return false;
@@ -1934,10 +1935,9 @@ bool RoseBuildImpl::addAnchoredAcyclic(const NGHolder &h) {
     flat_set<u32> added_lit_ids;          /* literal ids added for this NFA */
 
     for (auto v : inv_adjacent_vertices_range(h.accept, h)) {
-        // cppcheck-suppress useStlAlgorithm
         if (!prepAcceptForAddAnchoredNFA(*this, h, v, vertexDepths, depthMap,
                                          reportMap, allocated_reports,
-                                         added_lit_ids)) {
+                                         added_lit_ids)) { // cppcheck-suppress useStlAlgorithm
             removeAddedLiterals(*this, added_lit_ids);
             return false;
         }
index abfc71784af9e3ab394cac869924b80f9080e588..5a1d44fa8936d250a2b154ba48fb8ef99a535a48 100644 (file)
@@ -188,7 +188,7 @@ bool expandFmlCandidates(const CharReach &cr, vector<ue2_literal> &curr,
         }
     }
 
-    if (curr.back().length() > MAX_MASK2_WIDTH &&
+    if (!curr.empty() && curr.back().length() > MAX_MASK2_WIDTH &&
         any_of(begin(curr), end(curr), mixed_sensitivity)) {
         DEBUG_PRINTF("mixed-sensitivity lit is too long, stopping\n");
         return false;
index bb56c5bcd1400948ad1b570c032261d5ac36f4fc..9c7bb6fddc2ae06d2e031d81cc08abfdb93ed59f 100644 (file)
@@ -2457,6 +2457,7 @@ bool hasEodAnchors(const RoseBuildImpl &build, const build_context &bc,
     }
 
     const RoseGraph &g = build.g;
+    // cppcheck-suppress useStlAlgorithm
     for (auto v : vertices_range(g)) {
         if (g[v].eod_accept) {
             DEBUG_PRINTF("literally report eod\n");
@@ -2975,8 +2976,8 @@ void buildFragmentPrograms(const RoseBuildImpl &build,
         if (pfrag.included_frag_id != INVALID_FRAG_ID &&
             !lit_prog.empty()) {
             const auto &cfrag = fragments[pfrag.included_frag_id];
-            assert(pfrag.s.length() >= cfrag.s.length() &&
-                   !pfrag.s.any_nocase() >= !cfrag.s.any_nocase());
+            // cppcheck-suppress comparisonOfTwoFuncsReturningBoolError
+            assert(pfrag.s.length() >= cfrag.s.length() && !pfrag.s.any_nocase() >= !cfrag.s.any_nocase());
             u32 child_offset = cfrag.lit_program_offset;
             DEBUG_PRINTF("child %u offset %u\n", cfrag.fragment_id,
                          child_offset);
index ed06aeb1851162992b6ce0ca98312d77ed6fba4f..cf713c2fe3b6b96a3d290db51e4ac385600b7f3f 100644 (file)
@@ -1325,10 +1325,8 @@ void rehomeAnchoredLiteral(RoseBuildImpl &tbi, const simple_anchored_info &sai,
             /* ensure bounds on the vertex's in-edge are correct */
             assert(in_degree(v, tbi.g) == 1);
             const RoseEdge &e = *in_edges(v, tbi.g).first;
-            assert(tbi.g[e].minBound == sai.min_bound + sai.literal.length());
-            assert(tbi.g[e].maxBound == sai.max_bound + sai.literal.length());
-            tbi.g[e].minBound = sai.min_bound;
-            tbi.g[e].maxBound = sai.max_bound;
+            tbi.g[e].minBound = sai.min_bound; // cppcheck-suppress danglingTempReference
+            tbi.g[e].maxBound = sai.max_bound; // cppcheck-suppress danglingTempReference
         }
 
         /* mark the old literal as empty */
@@ -1632,6 +1630,7 @@ void addAnchoredSmallBlockLiterals(RoseBuildImpl &tbi) {
 #ifndef NDEBUG
 static
 bool historiesAreValid(const RoseGraph &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : edges_range(g)) {
         if (g[e].history == ROSE_ROLE_HISTORY_INVALID) {
             DEBUG_PRINTF("edge [%zu,%zu] has invalid history\n",
@@ -1648,7 +1647,7 @@ bool historiesAreValid(const RoseGraph &g) {
  * that no longer exists in the graph.
  */
 static
-bool danglingVertexRef(RoseBuildImpl &tbi) {
+bool danglingVertexRef(const RoseBuildImpl &tbi) {
     RoseGraph::vertex_iterator vi, ve;
     tie(vi, ve) = vertices(tbi.g);
     const unordered_set<RoseVertex> valid_vertices(vi, ve);
@@ -1659,6 +1658,7 @@ bool danglingVertexRef(RoseBuildImpl &tbi) {
         return true;
     }
 
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &e : tbi.ghost) {
         if (!contains(valid_vertices, e.first)) {
             DEBUG_PRINTF("ghost key vertex %zu not in graph\n",
@@ -1677,6 +1677,7 @@ bool danglingVertexRef(RoseBuildImpl &tbi) {
 
 static
 bool roleOffsetsAreValid(const RoseGraph &g) {
+    // cppcheck-suppress useStlAlgorithm
     for (auto v : vertices_range(g)) {
         if (g[v].min_offset >= ROSE_BOUND_INF) {
             DEBUG_PRINTF("invalid min_offset for role %zu\n", g[v].index);
index 7112910b20ec5e0d9a731efe4cf840fb1ed7e33a..5c485255f35dc4e653a1936329245b40210a2e59 100644 (file)
@@ -1421,6 +1421,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) {
                 os << "    base_offset " << ri->base_offset << endl;
                 os << "    last_start " << ri->last_start << endl;
                 os << "    fail_jump " << offset + ri->fail_jump << endl;
+               // cppcheck-suppress pointerOutOfBounds
                 dumpMultipathShufti(os, 16, ri->nib_mask, ri->nib_mask + 16,
                                     ri->bucket_select_mask,
                                     ri->data_select_mask,
@@ -1868,6 +1869,7 @@ void dumpComponentInfoCsv(const RoseEngine *t, const string &base) {
             }
         }
 
+       // cppcheck-suppress invalidPrintfArgType_sint
         fprintf(f, "%u,%zd,\"%s\",%u,%u,%u,%s,%s\n", i,
                 (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(t)), describe(*n).c_str(),
                 n->nPositions, n->streamStateSize, n->length,
index d87690267d60d46803c2a1b793adae57a5a7dfae..0371a011fdc13bac8b52d697d042cbbb715bb284 100644 (file)
@@ -140,6 +140,7 @@ static
 bool isSuffix(const vector<vector<CharReach>> &triggers1,
               const vector<vector<CharReach>> &triggers2) {
     // literal suffix test
+    // cppcheck-suppress useStlAlgorithm
     for (const auto &lit1 : triggers1) {
         // cppcheck-suppress useStlAlgorithm
         for (const auto &lit2 : triggers2) {
index a5225d3bd9481aae2f291c8c6e17f622045c3df2..cab0fad6dbd39e9820acebbefe5919e19ec370c4 100644 (file)
@@ -1027,6 +1027,7 @@ bool hasOrphanedTops(const RoseBuildImpl &build) {
     }
 
     for (const auto &e : leftfixes) {
+        // cppcheck-suppress useStlAlgorithm
         if (all_tops(e.first) != e.second) {
             DEBUG_PRINTF("rose tops (%s) don't match rose graph (%s)\n",
                          as_string_list(all_tops(e.first)).c_str(),
@@ -1036,6 +1037,7 @@ bool hasOrphanedTops(const RoseBuildImpl &build) {
     }
 
     for (const auto &e : suffixes) {
+        // cppcheck-suppress useStlAlgorithm
         if (all_tops(e.first) != e.second) {
             DEBUG_PRINTF("suffix tops (%s) don't match rose graph (%s)\n",
                          as_string_list(all_tops(e.first)).c_str(),
index a762520d98f56b9158ae47284b9904770abba277..60ff8384a7ec6709c8a3886774c2493619a20db7 100644 (file)
@@ -737,8 +737,8 @@ void pruneReportIfUnused(const RoseBuildImpl &build, shared_ptr<NGHolder> h,
     DEBUG_PRINTF("trying to prune %u from %p (v %zu)\n", report, h.get(),
                  verts.size());
     for (RoseVertex v : verts) {
-        // cppcheck-suppress useStlAlgorithm
         if (build.g[v].left.graph == h &&
+            // cppcheck-suppress useStlAlgorithm
             build.g[v].left.leftfix_report == report) {
             DEBUG_PRINTF("report %u still in use\n", report);
             return;
index e534859a4b58ee68d3db17a0f4525dfa4c0aef3c..156e1d71b0fb00405f2d937a944cbb5dd7d9a7a9 100644 (file)
@@ -65,7 +65,7 @@ u32 findMinWidth(const RoseBuildImpl &tbi, enum rose_literal_table table) {
     const RoseGraph &g = tbi.g;
 
     vector<RoseVertex> table_verts;
-    auto tvs = [&tbi=tbi, &table=table](const RoseVertex &v) {
+    auto tvs = [&tbi=tbi, table](const RoseVertex &v) {
         return (tbi.hasLiteralInTable(v, table));
     };
     const auto &vr = vertices_range(g);
@@ -189,7 +189,7 @@ u32 findMaxBAWidth(const RoseBuildImpl &tbi, enum rose_literal_table table) {
                   table == ROSE_FLOATING ? "floating" : "anchored");
 
     vector<RoseVertex> table_verts;
-    auto tvs = [&tbi=tbi, &table=table](const RoseVertex &v) {
+    auto tvs = [&tbi=tbi, table](const RoseVertex &v) {
         return ((table == ROSE_FLOATING && tbi.isFloating(v))
                || (table == ROSE_ANCHORED && tbi.isAnchored(v)));
     };
index 4ed5cef0c565e3a7bba0a52ebc769c0fdad69996..107e24ee0abd576fe96f9c32c4d0576327c2b348 100644 (file)
@@ -82,6 +82,7 @@ void dumpSomSlotManager(const SomSlotManager &ssm, const Grey &grey) {
             fprintf(f, "\t shared reset (users = %zu)\n", ir.entries.size());
         } else if (contains(by_slot, i)) {
             const SlotCacheEntry &ce = *by_slot.at(i);
+            // cppcheck-suppress knownConditionTrueFalse
             if (ce.parent_slot != SomSlotManager::NO_PARENT) {
                 fprintf(f, "\tparent:%u", ce.parent_slot);
             }
index 7f8539b090777e34262263b1493eb337bb028628..e1b605586cd76813fd63a668014310a4f47976c6 100644 (file)
@@ -270,22 +270,26 @@ static really_inline m128 andnot128(m128 a, m128 b) {
 // aligned load
 static really_inline m128 load128(const void *ptr) {
     assert(ISALIGNED_N(ptr, alignof(m128)));
+    // cppcheck-suppress cstyleCast
     return (m128) vld1q_s32((const int32_t *)ptr);
 }
 
 // aligned store
 static really_inline void store128(void *ptr, m128 a) {
     assert(ISALIGNED_N(ptr, alignof(m128)));
+    // cppcheck-suppress cstyleCast
     vst1q_s32((int32_t *)ptr, a);
 }
 
 // unaligned load
 static really_inline m128 loadu128(const void *ptr) {
+    // cppcheck-suppress cstyleCast
     return (m128) vld1q_s32((const int32_t *)ptr);
 }
 
 // unaligned store
 static really_inline void storeu128(void *ptr, m128 a) {
+    // cppcheck-suppress cstyleCast
     vst1q_s32((int32_t *)ptr, a);
 }
 
@@ -430,12 +434,14 @@ m128 sub_u8_m128(m128 a, m128 b) {
 static really_inline
 m128 set4x32(u32 x3, u32 x2, u32 x1, u32 x0) {
     uint32_t ALIGN_ATTR(16) data[4] = { x0, x1, x2, x3 };
+    // cppcheck-suppress cstyleCast
     return (m128) vld1q_u32((uint32_t *) data);
 }
 
 static really_inline
 m128 set2x64(u64a hi, u64a lo) {
     uint64_t ALIGN_ATTR(16) data[2] = { lo, hi };
+    // cppcheck-suppress cstyleCast
     return (m128) vld1q_u64((uint64_t *) data);
 }
 
index 15446e871c83e894e910fabf354de829f68b3088..9b6f7539bdd037d18ed0bf6f39354e05587a545b 100644 (file)
@@ -255,22 +255,26 @@ static really_inline m128 andnot128(m128 a, m128 b) {
 // aligned load
 static really_inline m128 load128(const void *ptr) {
     assert(ISALIGNED_N(ptr, alignof(m128)));
+    // cppcheck-suppress cstyleCast
     return (m128) vec_xl(0, (const int32_t*)ptr);
 }
 
 // aligned store
 static really_inline void store128(void *ptr, m128 a) {        
     assert(ISALIGNED_N(ptr, alignof(m128)));
+    // cppcheck-suppress cstyleCast
     vec_st(a, 0, (int32_t*)ptr);
 }
 
 // unaligned load
 static really_inline m128 loadu128(const void *ptr) {
+    // cppcheck-suppress cstyleCast
     return (m128) vec_xl(0, (const int32_t*)ptr);
 }
 
 // unaligned store
 static really_inline void storeu128(void *ptr, m128 a) {
+    // cppcheck-suppress cstyleCast
     vec_xst(a, 0, (int32_t*)ptr);
 }
 
index 5305c6f1b3371245e137012b188fcf2a6efc63a2..07d6ee03e210d68e910bb7f6667a2657451985be 100644 (file)
@@ -66,7 +66,6 @@ public:
 
     static depth unreachable() {
         depth d;
-        d.val = val_unreachable;
         return d;
     }
 
@@ -179,7 +178,7 @@ public:
         }
 
         s64a rv = val + d;
-        if (rv < 0 || (u64a)rv >= val_infinity) {
+        if ((u64a)rv >= val_infinity) {
             DEBUG_PRINTF("depth %lld too large to represent!\n", rv);
             throw DepthOverflowError();
         }
@@ -202,7 +201,7 @@ public:
         }
 
         s64a rv = val - d;
-        if (rv < 0 || (u64a)rv >= val_infinity) {
+        if ((u64a)rv >= val_infinity) {
             DEBUG_PRINTF("depth %lld too large to represent!\n", rv);
             throw DepthOverflowError();
         }
index 2243fcbd5e265672dc5dca6b8f25bf293a29504b..56466f1e9d682b3bac93ae94937fec3b81f7b6c9 100644 (file)
@@ -227,8 +227,6 @@ void describeClass(ostream &os, const CharReach &incr, size_t maxLength,
     int out_count = describeClassInt(out, incr, maxLength, out_type);
 
     std::ostringstream neg;
-    UNUSED int neg_count = describeClassInt(neg, ~incr, maxLength, out_type);
-
     if (out.tellp() <= neg.tellp()) {
         if (out_count > 1) {
             os << '[' << out.str() << ']';
index 9ba7e23210eaf41ee581e068db6bc967ceffbadb..b3dce4fa966de8789338c46c7af4a4e67def990d 100644 (file)
@@ -62,6 +62,7 @@ private:
 
 public:
     template <class OtherIter, class OtherValue>
+    // cppcheck-suppress noExplicitConstructor
     iter_wrapper(iter_wrapper<OtherIter, OtherValue> other,
                  typename std::enable_if<std::is_convertible<
                      OtherIter, WrappedIter>::value>::type * = nullptr)
index 507172847386454719e84eee63e8b52f90bbdb82..7ecd39af2b605854158af7aae4c34b289e7cc861 100644 (file)
@@ -146,7 +146,7 @@ public:
               adj_edge_iterator<Reverse>, edge_descriptor,
               boost::forward_traversal_tag, edge_descriptor> {
         vertex_descriptor u;
-        const base_type *g;
+        const base_type *g = nullptr;
         typename Traits::in_edge_iterator in_it;
         typename Traits::out_edge_iterator out_it;
         bool done_in = false;
@@ -238,7 +238,7 @@ public:
         : public boost::iterator_facade<edge_iterator, edge_descriptor,
                                         boost::forward_traversal_tag,
                                         edge_descriptor> {
-        const base_type *g;
+        const base_type *g = nullptr;
         typename Traits::edge_iterator it;
     public:
         edge_iterator() = default;
index 7121ab2bec47778b9bb2a6d87242f1efa3e3c10a..8ba15dcd1dea52bdf0dbd60ef777bfd61abb3be9 100644 (file)
@@ -64,6 +64,7 @@ public:
     template<class, class> friend class iter_wrapper;
 
     template<class OtherIter, class OtherValue>
+    // cppcheck-suppress noExplicitConstructor
     iter_wrapper(iter_wrapper<OtherIter, OtherValue> other,
                  typename std::enable_if<std::is_convertible<
                      OtherIter, WrappedIter>::value>::type * = nullptr)
index f697126396e506fdc3b707d56c65e139432b994b..30d015c0170feb670a53ca3d8f5d8df2cf9461ad 100644 (file)
@@ -228,6 +228,7 @@ public:
             assert(sub != INVALID_SUBSET);
             ENSURE_AT_LEAST(&subset_count, sub + 1);
         }
+        // cppcheck-suppress unsignedPositive
         assert(subset_count <= state_to_subset.size());
 
         subsets.resize(subset_count);
index 3b2cfa6be9191500ee1ca2f984bd233de9d69e0b..b2c692715d118f078b6c6e642c5897a46d52c022 100644 (file)
@@ -537,14 +537,14 @@ really_inline SuperVector<16> SuperVector<16>::Ones_vshl(uint8_t const N)
 template <>
 really_inline SuperVector<16> SuperVector<16>::loadu(void const *ptr)
 {
-    return SuperVector<16>(vec_xl(0, (const long64_t*)ptr));
+    return SuperVector<16>(vec_xl(0, reinterpret_cast<const long64_t*>(ptr)));
 }
 
 template <>
 really_inline SuperVector<16> SuperVector<16>::load(void const *ptr)
 {
     assert(ISALIGNED_N(ptr, alignof(SuperVector::size)));
-    return SuperVector<16>(vec_xl(0, (const long64_t*)ptr));
+    return SuperVector<16>(vec_xl(0, reinterpret_cast<const long64_t*>(ptr)));
 }
 
 template <>
index fddc2253166b8b93c0a5e990a806de40d9b7b3ef..38e55efe654492703827c943c2dabca568c500cf 100644 (file)
 #include "unaligned.h"
 
 // Aligned loads
-#ifndef __cplusplus__
+#ifndef __cplusplus
 #define load_u8(a)          (*(const u8 *)(a))
 #define load_u16(a)         (*(const u16 *)(a))
 #define load_u32(a)         (*(const u32 *)(a))
 #define load_u64a(a)        (*(const u64a *)(a))
 #else
-#define load_u8(a)          (*(reinterpret_cast<const u8 *>(a))
-#define load_u16(a)         (*(reinterpret_cast<const u16 *>(a))
-#define load_u32(a)         (*(reinterpret_cast<const u32 *>(a))
-#define load_u64a(a)        (*(reinterpret_cast<const u64a *>(a))
+#define load_u8(a)          (*(reinterpret_cast<const u8 *>(a)))
+#define load_u16(a)         (*(reinterpret_cast<const u16 *>(a)))
+#define load_u32(a)         (*(reinterpret_cast<const u32 *>(a)))
+#define load_u64a(a)        (*(reinterpret_cast<const u64a *>(a)))
 #endif // __cplusplus__
 #define load_m128(a)        load128(a)
 #define load_m256(a)        load256(a)
@@ -58,7 +58,7 @@
 #define load_m512(a)        load512(a)
 
 // Unaligned loads
-#ifndef __cplusplus__
+#ifndef __cplusplus
 #define loadu_u8(a)          (*(const u8 *)(a))
 #define loadu_u16(a)         unaligned_load_u16((const u8 *)(a))
 #define loadu_u32(a)         unaligned_load_u32((const u8 *)(a))
 #define loadu_u16(a)         unaligned_load_u16(reinterpret_cast<const u8 *>(a))
 #define loadu_u32(a)         unaligned_load_u32(reinterpret_cast<const u8 *>(a))
 #define loadu_u64a(a)        unaligned_load_u64a(reinterpret_cast<const u8 *>(a))
-#endif // __cplusplus__
+#endif // __cplusplus
 #define loadu_m128(a)        loadu128(a)
 #define loadu_m256(a)        loadu256(a)
 #define loadu_m384(a)        loadu384(a)
 #define loadu_m512(a)        loadu512(a)
 
 // Aligned stores
-#ifndef __cplusplus__
+#ifndef __cplusplus
+#define store_u8(ptr, a)    do { *((u8 *)(ptr)) = (a); } while(0)
+#define store_u16(ptr, a)   do { *((u16 *)(ptr)) = (a); } while(0)
+#define store_u32(ptr, a)   do { *((u32 *)(ptr)) = (a); } while(0)
+#define store_u64a(ptr, a)  do { *((u64a *)(ptr)) = (a); } while(0)
+#else
 #define store_u8(ptr, a)    do { *(reinterpret_cast<u8 *>(ptr)) = (a); } while(0)
 #define store_u16(ptr, a)   do { *(reinterpret_cast<u16 *>(ptr)) = (a); } while(0)
 #define store_u32(ptr, a)   do { *(reinterpret_cast<u32 *>(ptr)) = (a); } while(0)
 #define store_u64a(ptr, a)  do { *(reinterpret_cast<u64a *>(ptr)) = (a); } while(0)
-#else
-#endif // __cplusplus__
+#endif // __cplusplus
 #define store_m128(ptr, a)  store128(ptr, a)
 #define store_m256(ptr, a)  store256(ptr, a)
 #define store_m384(ptr, a)  store384(ptr, a)
 #define store_m512(ptr, a)  store512(ptr, a)
 
 // Unaligned stores
-#ifndef __cplusplus__
+#ifndef __cplusplus
 #define storeu_u8(ptr, a)    do { *(u8 *)(ptr) = (a); } while(0)
 #else
 #define storeu_u8(ptr, a)    do { *(reinterpret_cast<u8 *>(ptr)) = (a); } while(0)
-#endif // __cplusplus__
+#endif // __cplusplus
 #define storeu_u16(ptr, a)   unaligned_store_u16(ptr, a)
 #define storeu_u32(ptr, a)   unaligned_store_u32(ptr, a)
 #define storeu_u64a(ptr, a)  unaligned_store_u64a(ptr, a)
index 52ec11796a76643a0096f3dfd7e90a94dae89ab4..642ce75cbd8fa367391dfaf3d1fd9f364ea39664 100644 (file)
@@ -55,7 +55,7 @@ struct CompileCHStats {
 class EngineCHContext : public EngineContext{
 public:
     explicit EngineCHContext(const ch_database_t *db);
-    ~EngineCHContext();
+    virtual ~EngineCHContext() override;
 
     ch_scratch_t *scratch = nullptr;
 };
@@ -64,7 +64,7 @@ public:
 class EngineChimera : public Engine {
 public:
     explicit EngineChimera(ch_database_t *db, CompileCHStats cs);
-    ~EngineChimera();
+    virtual ~EngineChimera() override;
 
     std::unique_ptr<EngineContext> makeContext() const override;
 
index ccbc2fa8c9c0c5c97892ede94621f14dcccdf3c2..fa5174598e7b203d1fd33ef284d835522b813faf 100644 (file)
@@ -56,7 +56,7 @@ struct CompileHSStats {
 class EngineHSContext : public EngineContext {
 public:
     explicit EngineHSContext(const hs_database_t *db);
-    ~EngineHSContext();
+    virtual ~EngineHSContext() override;
 
     hs_scratch_t *scratch = nullptr;
 };
@@ -64,7 +64,7 @@ public:
 /** Streaming mode scans have persistent stream state associated with them. */
 class EngineHSStream : public EngineStream {
 public:
-    ~EngineHSStream();
+    virtual ~EngineHSStream() override;
     hs_stream_t *id = nullptr;
     EngineHSContext *ctx = nullptr;
 };
@@ -73,7 +73,7 @@ public:
 class EngineHyperscan : public Engine {
 public:
     explicit EngineHyperscan(hs_database_t *db, CompileHSStats cs);
-    ~EngineHyperscan();
+    virtual ~EngineHyperscan() override;
 
     std::unique_ptr<EngineContext> makeContext() const override;
 
index 7ae9147f4798f368e4229563f2f6e26884deab44..8f87fabbd6e340c62b201e95a0c9282455596596 100644 (file)
@@ -54,7 +54,7 @@ struct CompilePCREStats {
 class EnginePCREContext : public EngineContext{
 public:
     explicit EnginePCREContext(int capture_cnt);
-    ~EnginePCREContext();
+    virtual ~EnginePCREContext() override;
 
     int *ovec = nullptr;
 };
@@ -72,7 +72,7 @@ class EnginePCRE : public Engine {
 public:
     explicit EnginePCRE(std::vector<std::unique_ptr<PcreDB>> dbs_in,
                         CompilePCREStats cs, int capture_cnt_in);
-    ~EnginePCRE();
+    virtual ~EnginePCRE() override;
 
     std::unique_ptr<EngineContext> makeContext() const override;
 
index 857d5cad7c21c6ed36416f3e7ea987bd7a10286a..d0533ad6c3836479c33bb1e314245b9812b62954 100644 (file)
@@ -759,11 +759,9 @@ void displayResults(const vector<unique_ptr<ThreadContext>> &threads,
 
     // Sanity check: all of our results should have the same match count.
     for (const auto &t : threads) {
-        // cppcheck-suppress useStlAlgorithm
-        if (!all_of(begin(t->results), end(t->results),
-                    [&matchesPerRun](const ResultEntry &e) {
+        if (!all_of(begin(t->results), end(t->results), [&matchesPerRun](const ResultEntry &e) {
                         return e.matches == matchesPerRun;
-                    })) {
+                    })) { // cppcheck-suppress useStlAlgorithm
             printf("\nWARNING: PER-SCAN MATCH COUNTS ARE INCONSISTENT!\n\n");
             break;
         }
@@ -816,11 +814,9 @@ void displayCsvResults(const vector<unique_ptr<ThreadContext>> &threads,
 
     // Sanity check: all of our results should have the same match count.
     for (const auto &t : threads) {
-        // cppcheck-suppress useStlAlgorithm
-        if (!all_of(begin(t->results), end(t->results),
-                    [&matchesPerRun](const ResultEntry &e) {
+        if (!all_of(begin(t->results), end(t->results), [&matchesPerRun](const ResultEntry &e) {
                         return e.matches == matchesPerRun;
-                    })) {
+                    })) { // cppcheck-suppress useStlAlgorithm
             printf("\nWARNING: PER-SCAN MATCH COUNTS ARE INCONSISTENT!\n\n");
             break;
         }
@@ -871,11 +867,9 @@ void sqlResults(const vector<unique_ptr<ThreadContext>> &threads,
 
     // Sanity check: all of our results should have the same match count.
     for (const auto &t : threads) {
-        // cppcheck-suppress useStlAlgorithm
-        if (!all_of(begin(t->results), end(t->results),
-                    [&matchesPerRun](const ResultEntry &e) {
+        if (!all_of(begin(t->results), end(t->results), [&matchesPerRun](const ResultEntry &e) {
                         return e.matches == matchesPerRun;
-                    })) {
+                    })) { // cppcheck-suppress useStlAlgorithm
             printf("\nWARNING: PER-SCAN MATCH COUNTS ARE INCONSISTENT!\n\n");
             break;
         }
@@ -963,6 +957,7 @@ void runBenchmark(const Engine &db,
 
     for (unsigned i = 0; i < numThreads; i++) {
         auto t = makeThreadContext(db, corpus_blocks, i, sync_barrier);
+       // cppcheck-suppress knownConditionTrueFalse
         int core = useAffinity ? (int)threadCores[i] : -1;
         if (!t->start(core)) {
             printf("Unable to start processing thread %u\n", i);
index 6c8464b662b8fd935cd04827fa2ffa38f4b18a6c..0364b93ad49b8528ad9be2b6deb8623490411021 100644 (file)
@@ -143,7 +143,7 @@ void usage(const char *name, const char *error) {
 }
 
 static
-void processArgs(int argc, char *argv[], Grey &grey) {
+void processArgs(int argc, char *argv[], Grey &grey) { // cppcheck-suppress constParameterReference
     static const char *options = "d:De:E:G:hLNo:Ps:VXx:z:8";
     static struct option longOptions[] = {
         {"dump_db",             no_argument,        nullptr, 'D'},
@@ -294,7 +294,7 @@ void dumpDb(const struct hs_database *out, const Grey &grey) {
     size_t len = 0;
     hs_error_t err = hs_serialize_database(out, &bytes, &len);
     if (err != HS_SUCCESS) {
-        printf("ERROR: hs_serialize_database() failed with error %u\n", err);
+        printf("ERROR: hs_serialize_database() failed with error %d\n", err);
         return;
     }
 
@@ -331,7 +331,7 @@ void clearDir(const string &path) {
         exit(1);
     }
 
-    struct dirent *d_ent;
+    const struct dirent *d_ent;
     while (nullptr != (d_ent = readdir(dir))) {
         string name(d_ent->d_name);
         if (name == "." || name == "..") {
@@ -423,7 +423,7 @@ void dumpScratch(const hs_database_t *db, const Grey &grey) {
                    (grey.dumpPath + "scratch.txt").c_str(), strerror(errno));
         }
     } else {
-        printf("ERROR: hs_alloc_scratch() failed with error %u\n", err);
+        printf("ERROR: hs_alloc_scratch() failed with error %d\n", err);
     }
     hs_free_scratch(scratch);
 }
@@ -442,7 +442,7 @@ void dumpInfo(const hs_database_t *db, const Grey &grey) {
                    (grey.dumpPath + "db_info.txt").c_str(), strerror(errno));
         }
     } else {
-        printf("ERROR: hs_database_info() failed with error %u\n", err);
+        printf("ERROR: hs_database_info() failed with error %d\n", err);
     }
     free(info);
 }
@@ -482,7 +482,7 @@ unsigned int dumpDataMulti(const vector<const char *> &patterns,
         if (compile_err && compile_err->message) {
             printf("ERROR: Compile failed: %s\n", compile_err->message);
         } else {
-            printf("ERROR: hs_compile_multi_int() returned error %u", err);
+            printf("ERROR: hs_compile_multi_int() returned error %d", err);
         }
         hs_free_compile_error(compile_err);
         return 1;
index 09040bf92ebaafae61ffe94e159a9e514c8dbc6d..0477e9662bb9c536470be06121f2be6d5c3743b3 100644 (file)
@@ -192,6 +192,7 @@ void *count_malloc(size_t n) {
     *(reinterpret_cast<size_t *>(pp)) = n;
     void *p = static_cast<char *>(pp) + 16;
 
+    // cppcheck-suppress memleak
     return p;
 }
 
@@ -218,6 +219,7 @@ void *count_malloc_b(size_t n) {
     *(reinterpret_cast<size_t *>(pp)) = n;
     void *p = static_cast<char *>(pp) + 32;
 
+    // cppcheck-suppress memleak
     return p;
 }
 
index 377641d845a157e29d1b36c94d76e12270b1ad2e..c44cfe52b5ef5a7c5406d0bafa6b28d9c71817da 100644 (file)
@@ -98,7 +98,6 @@ TEST(ng_charreach, assignment) {
     cr2 = cr;
 
     ASSERT_EQ(cr.count(), cr2.count());
-    ASSERT_TRUE(cr == cr2);
 }
 
 TEST(ng_charreach, flip) {
index bc9547705ba5843ce33caeb50060605e95ea9962..3411064b15a215dc760ea80f0b8418b34e642335 100644 (file)
@@ -138,7 +138,7 @@ vector<u32> getValidFdrEngines() {
 
 
 static
-bytecode_ptr<FDR> buildFDREngineHinted(std::vector<hwlmLiteral> &lits,
+bytecode_ptr<FDR> buildFDREngineHinted(const std::vector<hwlmLiteral> &lits,
                                        bool make_small, u32 hint,
                                        const target_t &target,
                                        const Grey &grey) {
@@ -151,7 +151,7 @@ bytecode_ptr<FDR> buildFDREngineHinted(std::vector<hwlmLiteral> &lits,
 }
 
 static
-bytecode_ptr<FDR> buildFDREngine(std::vector<hwlmLiteral> &lits,
+bytecode_ptr<FDR> buildFDREngine(const std::vector<hwlmLiteral> &lits,
                                  bool make_small, const target_t &target,
                                  const Grey &grey) {
     auto proto = fdrBuildProto(HWLM_ENGINE_FDR, lits, make_small, target, grey);
index a3b0cc963daaffcecd2a28ea1ba0d0e8ea4fcaf7..dbfefb0028625058d616f49c74e5942656d53ead 100644 (file)
@@ -133,7 +133,7 @@ static vector<u32> getValidFdrEngines() {
 }
 
 static
-bytecode_ptr<FDR> buildFDREngineHinted(std::vector<hwlmLiteral> &lits,
+bytecode_ptr<FDR> buildFDREngineHinted(const std::vector<hwlmLiteral> &lits,
                                        bool make_small, u32 hint,
                                        const target_t &target,
                                        const Grey &grey) {
index 610c71e16862412d554195f8d245880cac94cfea..b5cc0f39ba4ffc48dc0eac798b625ea9f565bafd 100644 (file)
@@ -370,31 +370,24 @@ TEST(flat_map, get_allocator) {
 
 TEST(flat_map, compare_ops) {
     flat_map<u32, u32> f1 = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}};
-    flat_map<u32, u32> f1_copy = f1;
     flat_map<u32, u32> f2 = {{2, 1}, {4, 2}, {6, 3}, {8, 4}, {10, 5}, {12, 6}};
 
     EXPECT_TRUE(f1 == f1);
-    EXPECT_TRUE(f1 == f1_copy);
     EXPECT_FALSE(f1 == f2);
 
     EXPECT_FALSE(f1 != f1);
-    EXPECT_FALSE(f1 != f1_copy);
     EXPECT_TRUE(f1 != f2);
 
     EXPECT_FALSE(f1 < f1);
-    EXPECT_FALSE(f1 < f1_copy);
     EXPECT_TRUE(f1 < f2);
 
     EXPECT_TRUE(f1 <= f1);
-    EXPECT_TRUE(f1 <= f1_copy);
     EXPECT_TRUE(f1 <= f2);
 
     EXPECT_FALSE(f1 > f1);
-    EXPECT_FALSE(f1 > f1_copy);
     EXPECT_FALSE(f1 > f2);
 
     EXPECT_TRUE(f1 >= f1);
-    EXPECT_TRUE(f1 >= f1_copy);
     EXPECT_FALSE(f1 >= f2);
 }
 
index 174a4771d092eeca2c68726524261fa79b4b1960..e0c84ceb3bb172ab88566d96702dc3861fa40657 100644 (file)
@@ -340,31 +340,24 @@ TEST(flat_set, iter_interop) {
 
 TEST(flat_set, compare_ops) {
     flat_set<u32> f1 = {1, 2, 3, 4, 5};
-    flat_set<u32> f1_copy = f1;
     flat_set<u32> f2 = {2, 4, 6, 8, 10};
 
     EXPECT_TRUE(f1 == f1);
-    EXPECT_TRUE(f1 == f1_copy);
     EXPECT_FALSE(f1 == f2);
 
     EXPECT_FALSE(f1 != f1);
-    EXPECT_FALSE(f1 != f1_copy);
     EXPECT_TRUE(f1 != f2);
 
     EXPECT_FALSE(f1 < f1);
-    EXPECT_FALSE(f1 < f1_copy);
     EXPECT_TRUE(f1 < f2);
 
     EXPECT_TRUE(f1 <= f1);
-    EXPECT_TRUE(f1 <= f1_copy);
     EXPECT_TRUE(f1 <= f2);
 
     EXPECT_FALSE(f1 > f1);
-    EXPECT_FALSE(f1 > f1_copy);
     EXPECT_FALSE(f1 > f2);
 
     EXPECT_TRUE(f1 >= f1);
-    EXPECT_TRUE(f1 >= f1_copy);
     EXPECT_FALSE(f1 >= f2);
 }
 
index d017f8a55cbf1e0e0614fd8032c9d6528906699d..0f324c12480a42a32a62861e2274866965cd0b92 100644 (file)
@@ -55,11 +55,11 @@ public:
     }
     operator u8 *() {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
     operator const u8 *() const {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
 
 private:
index 5c65d0a9b0f25defd41267624ea46efb2ed06570..b1d5b7840f4dde94ad0a196ed7fb5a9be1ee1639 100644 (file)
@@ -94,11 +94,11 @@ public:
     }
     operator u8 *() {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
     operator const u8 *() const {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
 
 private:
@@ -116,11 +116,11 @@ public:
     }
     operator u8 *() {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
     operator const u8 *() const {
         assert(data);
-        return data.get() + 7;
+        return reinterpret_cast<u8 *>(data.get()) + 7;
     }
 
 private:
index b1792e1c06c2c2af982745f814ac1fb68c6f03b4..73098f6d4300e8227e7ede120abfa89560dda5c0 100644 (file)
@@ -66,6 +66,7 @@ ostream& operator<<(ostream &os, const RepeatInfo &info) {
 
 class RepeatTest : public TestWithParam<RepeatTestInfo> {
 protected:
+    RepeatTest() = default;
     virtual void SetUp() {
         test_info = GetParam();
 
@@ -94,12 +95,12 @@ protected:
         delete [] state_int;
     }
 
-    RepeatTestInfo test_info; // Test params
-    RepeatInfo info; // Repeat info structure
-    RepeatControl *ctrl;
-    char *state;
+    RepeatTestInfo test_info{}; // Test params
+    RepeatInfo info{}; // Repeat info structure
+    RepeatControl *ctrl = nullptr;
+    char *state = nullptr;
 private:
-    char *state_int;
+    char *state_int = nullptr;
 
 };
 
@@ -728,6 +729,7 @@ void test_sparse3entryExpire(const RepeatInfo *info, RepeatControl *ctrl,
 
 class SparseOptimalTest : public TestWithParam<tuple<u32, RepeatTestInfo> > {
 protected:
+    SparseOptimalTest() = default;
     virtual void SetUp() {
         u32 period;
         tie(period, test_info) = GetParam();
@@ -773,13 +775,13 @@ protected:
         delete[] ptr;
     }
 
-    RepeatTestInfo test_info; // Test params
-    RepeatInfo *info; // Repeat info structure
-    RepeatControl *ctrl;
-    char *state;
+    RepeatTestInfo test_info{}; // Test params
+    RepeatInfo *info = nullptr; // Repeat info structure
+    RepeatControl *ctrl = nullptr;
+    char *state = nullptr;
 private:
-    char *ptr;
-    char *state_int;
+    char *ptr = nullptr;
+    char *state_int = nullptr;
 
 };
 
index e13abb673c0583fd91a5d087df6b1433009f1c57..cb195eaf1a152632f193bc37ee2dd2e146a20cd9 100644 (file)
@@ -223,7 +223,7 @@ class CorpusGeneratorImpl : public CorpusGenerator {
 public:
     CorpusGeneratorImpl(const NGHolder &graph_in, const ExpressionInfo &expr_in,
                         CorpusProperties &props);
-    virtual ~CorpusGeneratorImpl() = default;
+    virtual ~CorpusGeneratorImpl() override = default;
 
     void generateCorpus(vector<string> &data) override;
 
@@ -419,7 +419,7 @@ class CorpusGeneratorUtf8 : public CorpusGenerator {
 public:
     CorpusGeneratorUtf8(const NGHolder &graph_in, const ExpressionInfo &expr_in,
                         CorpusProperties &props);
-    ~CorpusGeneratorUtf8() = default;
+    virtual ~CorpusGeneratorUtf8() override = default;
 
     void generateCorpus(vector<string> &data) override;