]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Various cppcheck fixes (#337)
authorKonstantinos Margaritis <markos@users.noreply.github.com>
Fri, 30 May 2025 09:27:28 +0000 (12:27 +0300)
committerGitHub <noreply@github.com>
Fri, 30 May 2025 09:27:28 +0000 (12:27 +0300)
benchmarks/benchmarks.cpp
cppcheck-suppression-list.txt
src/nfa/lbr.c
src/nfa/lbr_common_impl.h
src/nfagraph/ng_repeat.cpp
src/rose/rose_build_dump.cpp
src/rose/rose_build_program.cpp
src/rose/rose_build_program.h
unit/internal/fdr.cpp
unit/internal/fdr_flood.cpp
util/string_util.h

index 81402994448c27909746f5fa22524dbca7c467dc..3bcd3f88319a33f2c6eff14d5a5a17d0df0f4f56 100644 (file)
@@ -51,7 +51,7 @@ struct hlmMatchEntry {
 std::vector<hlmMatchEntry> ctxt;
 
 static hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id,
-                                     UNUSED struct hs_scratch *scratch) {
+                                     UNUSED struct hs_scratch *scratch) { // cppcheck-suppress constParameterCallback
     DEBUG_PRINTF("match @%zu = %u\n", to, id);
 
     ctxt.push_back(hlmMatchEntry(to, id));
@@ -152,7 +152,7 @@ int main(){
                                           reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return shuftiExec(b.truffle_mask_lo, b.truffle_mask_hi, b.buf.data(),
                                       b.buf.data() + b.size);
                 });
@@ -169,7 +169,7 @@ int main(){
                                           reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return rshuftiExec(b.truffle_mask_lo, b.truffle_mask_hi, b.buf.data(),
                                        b.buf.data() + b.size);
                 });
@@ -186,7 +186,7 @@ int main(){
                                            reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return truffleExec(b.truffle_mask_lo, b.truffle_mask_hi, b.buf.data(),
                                        b.buf.data() + b.size);
                 });
@@ -203,7 +203,7 @@ int main(){
                                            reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return rtruffleExec(b.truffle_mask_lo, b.truffle_mask_hi, b.buf.data(),
                                         b.buf.data() + b.size);
                 });
@@ -218,7 +218,7 @@ int main(){
                         ue2::truffleBuildMasksWide(b.chars, reinterpret_cast<u8 *>(&b.truffle_mask));
                         memset(b.buf.data(), 'b', b.size);
                     },
-                    [&](MicroBenchmark &b) {
+                    [&](MicroBenchmark const &b) {
                         return truffleExecWide(b.truffle_mask, b.buf.data(), b.buf.data() + b.size);
                     }
                 );
@@ -232,7 +232,7 @@ int main(){
                         ue2::truffleBuildMasksWide(b.chars, reinterpret_cast<u8 *>(&b.truffle_mask));
                         memset(b.buf.data(), 'b', b.size);
                     },
-                    [&](MicroBenchmark &b) {
+                    [&](MicroBenchmark const &b) {
                         return rtruffleExecWide(b.truffle_mask, b.buf.data(), b.buf.data() + b.size);
                     }
                 );
@@ -251,7 +251,7 @@ int main(){
                                            reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return vermicelliExec('a', 'b', b.buf.data(),
                                           b.buf.data() + b.size);
                 });
@@ -268,7 +268,7 @@ int main(){
                                            reinterpret_cast<u8 *>(&b.truffle_mask_hi));
                     memset(b.buf.data(), 'b', b.size);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark const &b) {
                     return rvermicelliExec('a', 'b', b.buf.data(),
                                            b.buf.data() + b.size);
                 });
@@ -297,7 +297,7 @@ int main(){
                     b.nt = ue2::noodBuildTable(lit);
                     assert(b.nt.get() != nullptr);
                 },
-                [&](MicroBenchmark &b) {
+                [&](MicroBenchmark &b) { // cppcheck-suppress constParameterReference
                     noodExec(b.nt.get(), b.buf.data(), b.size, 0,
                              hlmSimpleCallback, &b.scratch);
                     return b.buf.data() + b.size;
index 79c73fe94ac0f1d0a413c4c7a30ae22321698560..b2fdd08da7efb678cca201b957c9443fa298b9ed 100644 (file)
@@ -2,7 +2,9 @@ unknownMacro:*gtest-all.cc
 knownConditionTrueFalse:*Parser.rl
 knownConditionTrueFalse:*Parser.cpp
 variableScope:*Parser.rl
+duplicateBreak:*.rl
 unreadVariable:*control_verbs.cpp
+unreachableCode:*rose_build_dump.cpp
 *:*simde/*
 assertWithSideEffect
 syntaxError
@@ -10,4 +12,4 @@ internalError
 checkersReport
 missingInclude
 missingIncludeSystem
-unmatchedSuppression
\ No newline at end of file
+unmatchedSuppression
index 52e81ad6776c4e351f6ea9311a3841f51012330f..c3bd8a57aac8200fdcde4bc4fa5f9274196e730b 100644 (file)
@@ -307,7 +307,7 @@ char lbrMatchLoop(const struct lbr_common *l, const u64a begin, const u64a end,
 static really_inline
 char lbrRevScanDot(UNUSED const struct NFA *nfa, UNUSED const u8 *buf,
                    UNUSED size_t begin, UNUSED size_t end,
-                   UNUSED size_t *loc) {
+                   UNUSED const size_t *loc) {
     assert(begin <= end);
     assert(nfa->type == LBR_NFA_DOT);
     // Nothing can kill a dot!
@@ -413,7 +413,7 @@ char lbrRevScanTruf(const struct NFA *nfa, const u8 *buf,
 static really_inline
 char lbrFwdScanDot(UNUSED const struct NFA *nfa, UNUSED const u8 *buf,
                    UNUSED size_t begin, UNUSED size_t end,
-                   UNUSED size_t *loc) {
+                   UNUSED const size_t *loc) {
     assert(begin <= end);
     assert(nfa->type == LBR_NFA_DOT);
     // Nothing can kill a dot!
index 4f530e6decfe8af914b17ada5e0ab17a8967e094..8bffa1fc63cd05c4c51e68382551a4ca00cb28b6 100644 (file)
@@ -180,7 +180,7 @@ found_top:;
 
         u64a ep = MIN(MIN(end, (s64a)q->length) + offset, first_match);
         if (ep > sp && sp >= offset) {
-            size_t eloc;
+            size_t eloc = 0;
             DEBUG_PRINTF("rev b%llu e%llu/%zu\n", sp - offset, ep - offset,
                          q->length);
             assert(ep - offset <= q->length);
index b94e22a1988f573d6a838d6dd5f44230a49e2ed9..4a1c6d308b84fc999867030cf295cea2ae47ae48 100644 (file)
@@ -662,7 +662,7 @@ void buildTugTrigger(NGHolder &g, NFAVertex cyclic, NFAVertex v,
 }
 
 static
-NFAVertex createCyclic(NGHolder &g, ReachSubgraph &rsi) {
+NFAVertex createCyclic(NGHolder &g, ReachSubgraph const &rsi) {
     NFAVertex last = rsi.vertices.back();
     NFAVertex cyclic = clone_vertex(g, last);
     add_edge(cyclic, cyclic, g);
@@ -672,7 +672,7 @@ NFAVertex createCyclic(NGHolder &g, ReachSubgraph &rsi) {
 }
 
 static
-NFAVertex createPos(NGHolder &g, ReachSubgraph &rsi) {
+NFAVertex createPos(NGHolder &g, ReachSubgraph const &rsi) {
     NFAVertex pos = add_vertex(g);
     NFAVertex first = rsi.vertices.front();
 
index 5c485255f35dc4e653a1936329245b40210a2e59..ad57dfc6c9e29b066dc29c216576b50529a16bae 100644 (file)
@@ -861,7 +861,7 @@ void dumpMultipathShufti(ofstream &os, u32 len, const u8 *lo, const u8 *hi,
     os << endl;
 }
 
-           #define PROGRAM_CASE(name)                                                     \
+#define PROGRAM_CASE(name)                                                     \
     case ROSE_INSTR_##name: {                                                  \
         os << "  " << std::setw(4) << std::setfill('0') << (pc - pc_base)      \
            << ": " #name "\n";                                                 \
index 11c7aba364a0cd0e0515f6514c3aff95211069d7..4b7251461b1142a8c83f5bfa01346502c16d7539 100644 (file)
@@ -763,7 +763,7 @@ void makeRoleSetState(const unordered_map<RoseVertex, u32> &roleStateIndices,
 
 static
 void makePushDelayedInstructions(const RoseLiteralMap &literals,
-                                 ProgramBuild &prog_build,
+                                 ProgramBuild const &prog_build,
                                  const flat_set<u32> &delayed_ids,
                                  RoseProgram &program) {
     vector<RoseInstrPushDelayed> delay_instructions;
@@ -903,7 +903,7 @@ void makeRoleCheckBounds(const RoseBuildImpl &build, RoseVertex v,
 }
 
 static
-void makeRoleGroups(const RoseGraph &g, ProgramBuild &prog_build,
+void makeRoleGroups(const RoseGraph &g, ProgramBuild const &prog_build,
                     RoseVertex v, RoseProgram &program) {
     rose_group groups = g[v].groups;
     if (!groups) {
@@ -1020,7 +1020,7 @@ bool makeRoleMask(const vector<LookEntry> &look, RoseProgram &program) {
 }
 
 static UNUSED
-string convertMaskstoString(u8 *p, int byte_len) {
+string convertMaskstoString(u8 const *p, int byte_len) {
     string s;
     for (int i = 0; i < byte_len; i++) {
         u8 hi = *p >> 4;
@@ -1625,7 +1625,7 @@ bool hasDelayedLiteral(const RoseBuildImpl &build,
 
 static
 RoseProgram makeLitInitialProgram(const RoseBuildImpl &build,
-                                  ProgramBuild &prog_build, u32 lit_id,
+                                  ProgramBuild const &prog_build, u32 lit_id,
                                   const vector<RoseEdge> &lit_edges,
                                   bool is_anchored_replay_program) {
     RoseProgram program;
@@ -2309,7 +2309,7 @@ RoseProgram makeLiteralProgram(const RoseBuildImpl &build,
 }
 
 RoseProgram makeDelayRebuildProgram(const RoseBuildImpl &build,
-                                    ProgramBuild &prog_build,
+                                    ProgramBuild const &prog_build,
                                     const vector<u32> &lit_ids) {
     assert(!lit_ids.empty());
     assert(build.cc.streaming);
index b8323dc810c420415a42725880a0e8083ffd711b..c81feb716880d0a82cfbdd452125ca2c8ccdf69d 100644 (file)
@@ -243,7 +243,7 @@ RoseProgram makeLiteralProgram(const RoseBuildImpl &build,
                     bool is_anchored_replay_program);
 
 RoseProgram makeDelayRebuildProgram(const RoseBuildImpl &build,
-                                    ProgramBuild &prog_build,
+                                    ProgramBuild const &prog_build,
                                     const std::vector<u32> &lit_ids);
 
 RoseProgram makeEodAnchorProgram(const RoseBuildImpl &build,
index 3411064b15a215dc760ea80f0b8418b34e642335..92340d5151a65ae0468728f7458294e5226779a6 100644 (file)
@@ -93,7 +93,7 @@ extern "C" {
 
 static
 hwlmcb_rv_t decentCallback(size_t end, u32 id,
-                           UNUSED struct hs_scratch *scratch) {
+                           UNUSED struct hs_scratch *scratch) {  // cppcheck-suppress constParameterCallback
     DEBUG_PRINTF("match @%zu : %u\n", end, id);
 
     matches.push_back(match(end, id));
@@ -102,7 +102,7 @@ hwlmcb_rv_t decentCallback(size_t end, u32 id,
 
 static
 hwlmcb_rv_t decentCallbackT(size_t end, u32 id,
-                            UNUSED struct hs_scratch *scratch) {
+                            UNUSED struct hs_scratch *scratch) { // cppcheck-suppress constParameterCallback
     matches.push_back(match(end, id));
     return HWLM_TERMINATE_MATCHING;
 }
index dbfefb0028625058d616f49c74e5942656d53ead..e2f48fe929965816146b1c9043ea346dac18c386 100644 (file)
@@ -101,7 +101,7 @@ map<u32, int> matchesCounts;
 extern "C" {
 
 static hwlmcb_rv_t countCallback(UNUSED size_t end, u32 id,
-                                 UNUSED struct hs_scratch *scratch) {
+                                 UNUSED struct hs_scratch *scratch) { // cppcheck-suppress constParameterCallback
     matchesCounts[id]++;
     return HWLM_CONTINUE_MATCHING;
 }
index 04d778af8730f29be78cc58dc1571206eb2af43c..a3ceeff8d83dff1665f5be2852862be8d73e2cf9 100644 (file)
@@ -142,9 +142,9 @@ static really_inline
 char *makeHex(const unsigned char *pat, unsigned patlen) {
     size_t hexlen = patlen * 4;
     char *hexbuf = reinterpret_cast<char *>(malloc(hexlen + 1));
-    unsigned i;
-    char *buf;
-    for (i = 0, buf = hexbuf; i < patlen; i++, buf += 4) {
+    if (!hexbuf) abort();
+    char *buf = hexbuf;
+    for (size_t i = 0; i < patlen; i++, buf += 4) {
         snprintf(buf, 5, "\\x%02x", (unsigned char)pat[i]);
     }
     hexbuf[hexlen] = '\0';