From d23e4a12e74d396b72bb6defaba961c16ee049e6 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Tue, 28 May 2024 14:15:03 +0300 Subject: [PATCH 1/8] cplusplus.Move --- util/ng_corpus_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ng_corpus_generator.cpp b/util/ng_corpus_generator.cpp index cb195eaf..69e7c4ef 100644 --- a/util/ng_corpus_generator.cpp +++ b/util/ng_corpus_generator.cpp @@ -185,7 +185,7 @@ void findPaths(const NGHolder &g, CorpusProperties &cProps, continue; } - if (!contains(one_way_in, v) && + if (p && !contains(one_way_in, v) && has_greater_than(p->begin(), p->end(), v, cycleLimit)) { // Note that vertices that only have one predecessor don't need // their cycle limit checked, as their predecessors will have From faa9e7549f2f2ba9025db1bb0f745ee028792f56 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Wed, 29 May 2024 11:51:06 +0300 Subject: [PATCH 2/8] uninitialized.UndefReturn --- src/util/ue2_graph.h | 3 +++ src/util/unaligned.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/util/ue2_graph.h b/src/util/ue2_graph.h index 52910520..9d9f22d1 100644 --- a/src/util/ue2_graph.h +++ b/src/util/ue2_graph.h @@ -796,6 +796,9 @@ public: explicit prop_map(value_type P_of::*m_in) : member(m_in) { } reference operator[](key_type k) const { + if (k.raw() == nullptr || &(k.raw()->props) == nullptr) { + throw std::invalid_argument("Invalid key"); + } return k.raw()->props.*member; } reference operator()(key_type k) const { return (*this)[k]; } diff --git a/src/util/unaligned.h b/src/util/unaligned.h index 3f662de1..e4c77900 100644 --- a/src/util/unaligned.h +++ b/src/util/unaligned.h @@ -58,6 +58,9 @@ u32 unaligned_load_u32(const void *ptr) { /// Perform an unaligned 64-bit load static really_inline u64a unaligned_load_u64a(const void *ptr) { + if (ptr == NULL) { + return 0; // Return a default value + } struct unaligned { u64a u; } PACKED__MAY_ALIAS; // cppcheck-suppress cstyleCast const struct unaligned *uptr = (const struct unaligned *)ptr; From de1697b467edd9ec2bb0eebb0cee7349f3baa1be Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Thu, 30 May 2024 16:40:18 +0300 Subject: [PATCH 3/8] deadcode.DeadStores --- src/nfa/mcclellan_common_impl.h | 1 - src/nfa/sheng_impl.h | 2 +- src/nfa/sheng_impl4.h | 8 ++++---- src/rose/program_runtime.c | 4 ++-- unit/hyperscan/expr_info.cpp | 2 +- unit/hyperscan/single.cpp | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/nfa/mcclellan_common_impl.h b/src/nfa/mcclellan_common_impl.h index 6ec1b1f1..14a71d3f 100644 --- a/src/nfa/mcclellan_common_impl.h +++ b/src/nfa/mcclellan_common_impl.h @@ -134,7 +134,6 @@ u16 doWide16(const char *wide_entry, const u8 **c_inout, const u8 *end, len_c -= 16; } - pos = 0; // at least one in (0, 16). u32 loadLength_w = MIN(len_w, 16); u32 loadLength_c = MIN(len_c, 16); diff --git a/src/nfa/sheng_impl.h b/src/nfa/sheng_impl.h index 2c701446..8b22d810 100644 --- a/src/nfa/sheng_impl.h +++ b/src/nfa/sheng_impl.h @@ -67,7 +67,7 @@ char SHENG_IMPL(u8 *state, NfaCallback cb, void *ctxt, const struct sheng *s, if (unlikely(ACCEPT_FUNC(tmp))) { DEBUG_PRINTF("Accept state %u reached\n", tmp & SHENG_STATE_MASK); - u64a match_offset = base_offset + (cur_buf - buf) + 1; + u64a match_offset = base_offset + (cur_buf - buf) + 1; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Match @ %llu\n", match_offset); if (STOP_AT_MATCH) { DEBUG_PRINTF("Stopping at match @ %lli\n", diff --git a/src/nfa/sheng_impl4.h b/src/nfa/sheng_impl4.h index 718c3409..d2b3dc35 100644 --- a/src/nfa/sheng_impl4.h +++ b/src/nfa/sheng_impl4.h @@ -129,7 +129,7 @@ char SHENG_IMPL(u8 *state, NfaCallback cb, void *ctxt, const struct sheng *s, if (unlikely(INTERESTING_FUNC(a1, a2, a3, a4))) { if (ACCEPT_FUNC(a1)) { - u64a match_offset = base_offset + b1 - buf; + u64a match_offset = base_offset + b1 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a1 & SHENG_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -154,7 +154,7 @@ char SHENG_IMPL(u8 *state, NfaCallback cb, void *ctxt, const struct sheng *s, } } if (ACCEPT_FUNC(a2)) { - u64a match_offset = base_offset + b2 - buf; + u64a match_offset = base_offset + b2 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a2 & SHENG_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -179,7 +179,7 @@ char SHENG_IMPL(u8 *state, NfaCallback cb, void *ctxt, const struct sheng *s, } } if (ACCEPT_FUNC(a3)) { - u64a match_offset = base_offset + b3 - buf; + u64a match_offset = base_offset + b3 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a3 & SHENG_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -204,7 +204,7 @@ char SHENG_IMPL(u8 *state, NfaCallback cb, void *ctxt, const struct sheng *s, } } if (ACCEPT_FUNC(a4)) { - u64a match_offset = base_offset + b4 - buf; + u64a match_offset = base_offset + b4 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a4 & SHENG_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); diff --git a/src/rose/program_runtime.c b/src/rose/program_runtime.c index 87dc0c4d..bedc8264 100644 --- a/src/rose/program_runtime.c +++ b/src/rose/program_runtime.c @@ -2991,7 +2991,7 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, pc = getByOffset(t, ri->child_offset); pc_base = pc; - programOffset = (const u8 *)pc_base -(const u8 *)t; + programOffset = (const u8 *)pc_base -(const u8 *)t; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("pc_base %p pc %p child_offset %u squash %u\n", pc_base, pc, ri->child_offset, ri->squash); work_done = 0; @@ -3428,7 +3428,7 @@ hwlmcb_rv_t roseRunProgram_l(const struct RoseEngine *t, pc = getByOffset(t, ri->child_offset); pc_base = pc; - programOffset = (const u8 *)pc_base -(const u8 *)t; + programOffset = (const u8 *)pc_base -(const u8 *)t; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("pc_base %p pc %p child_offset %u squash %u\n", pc_base, pc, ri->child_offset, ri->squash); work_done = 0; diff --git a/unit/hyperscan/expr_info.cpp b/unit/hyperscan/expr_info.cpp index 0ea8bce5..647714e2 100644 --- a/unit/hyperscan/expr_info.cpp +++ b/unit/hyperscan/expr_info.cpp @@ -89,7 +89,7 @@ ostream& operator<<(ostream &os, const hs_expr_ext &ext) { os << ", "; } os << "hamming_distance=" << ext.hamming_distance; - first = false; + //first = false; } return os; } diff --git a/unit/hyperscan/single.cpp b/unit/hyperscan/single.cpp index 278d28f7..3f916c91 100644 --- a/unit/hyperscan/single.cpp +++ b/unit/hyperscan/single.cpp @@ -571,7 +571,7 @@ TEST_P(HyperscanTestMatchTerminate, StreamWhole) { terminateHandler, &count); ASSERT_TRUE(err == HS_SUCCESS || err == HS_SCAN_TERMINATED); - err = hs_close_stream(stream, scratch, terminateHandler, &count); + hs_close_stream(stream, scratch, terminateHandler, &count); ASSERT_EQ(1, count) << "Number of matches returned was not 1."; err = hs_free_scratch(scratch); @@ -600,7 +600,7 @@ TEST_P(HyperscanTestMatchTerminate, StreamByteByByte) { ASSERT_TRUE(err == HS_SUCCESS || err == HS_SCAN_TERMINATED); } - err = hs_close_stream(stream, scratch, terminateHandler, &count); + hs_close_stream(stream, scratch, terminateHandler, &count); ASSERT_EQ(1, count) << "Number of matches returned was not 1."; err = hs_free_scratch(scratch); From 9c0beb57f8cef66c823e20786537f3af80d4a851 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Thu, 30 May 2024 16:40:47 +0300 Subject: [PATCH 4/8] deadcode.DeadStores --- tools/hsbench/heapstats.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/hsbench/heapstats.cpp b/tools/hsbench/heapstats.cpp index 5fba7c2a..335b21eb 100644 --- a/tools/hsbench/heapstats.cpp +++ b/tools/hsbench/heapstats.cpp @@ -72,9 +72,8 @@ size_t getPeakHeap(void) { char *line = nullptr; size_t len = 0, maxheap = 0; - ssize_t read; - while ((read = getline(&line, &len, fstr)) != -1) { + while ((getline(&line, &len, fstr)) != -1) { if (strncmp(line, begin, begin_len) == 0) { errno = 0; maxheap = (size_t)strtoull(line + begin_len, nullptr, 10); From c5c4c5d5f5034ce3300e99f9a3a745acc5fa1649 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Thu, 30 May 2024 16:40:55 +0300 Subject: [PATCH 5/8] clang-analyzer-cplusplus.NewDelete --- src/util/pack_bits.h | 3 +-- src/util/partial_store.h | 4 ++-- src/util/unaligned.h | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/util/pack_bits.h b/src/util/pack_bits.h index 800ce25e..9c1ee157 100644 --- a/src/util/pack_bits.h +++ b/src/util/pack_bits.h @@ -190,7 +190,6 @@ static really_inline void unpack_bits_64(u64a *v, const u8 *in, const u32 *bits, const unsigned int elements) { u32 used = 0; // bits used from *in - for (unsigned int i = 0; i < elements; i++) { assert(bits[i] <= 64); u64a v_out = 0; // accumulator for v[i] @@ -198,7 +197,7 @@ void unpack_bits_64(u64a *v, const u8 *in, const u32 *bits, u32 vidx = 0; // bits written to v[i] while (b) { - u64a read = *in >> used; + u64a read = *in >> used; //NOLINT (clang-analyzer-cplusplus.NewDelete) u32 bits_read = 8 - used; if (b <= bits_read) { diff --git a/src/util/partial_store.h b/src/util/partial_store.h index efe357cc..a75a1be6 100644 --- a/src/util/partial_store.h +++ b/src/util/partial_store.h @@ -122,7 +122,7 @@ void partial_store_u64a(void *ptr, u64a value, u32 numBytes) { break; case 1: // cppcheck-suppress cstyleCast - *(u8 *)ptr = (u8)value; + *(u8 *)ptr = (u8)value; //NOLINT (clang-analyzer-cplusplus.NewDelete) break; case 0: break; @@ -167,7 +167,7 @@ u64a partial_load_u64a(const void *ptr, u32 numBytes) { return value; case 1: // cppcheck-suppress cstyleCast - value = *(const u8 *)ptr; + value = *(const u8 *)ptr; return value; case 0: break; diff --git a/src/util/unaligned.h b/src/util/unaligned.h index e4c77900..661750a7 100644 --- a/src/util/unaligned.h +++ b/src/util/unaligned.h @@ -73,7 +73,7 @@ void unaligned_store_u16(void *ptr, u16 val) { struct unaligned { u16 u; } PACKED__MAY_ALIAS; // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; - uptr->u = val; + uptr->u = val; //NOLINT (clang-analyzer-cplusplus.NewDelete) } /// Perform an unaligned 32-bit store @@ -82,7 +82,7 @@ void unaligned_store_u32(void *ptr, u32 val) { struct unaligned { u32 u; } PACKED__MAY_ALIAS; // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; - uptr->u = val; + uptr->u = val; //NOLINT (clang-analyzer-cplusplus.NewDelete) } /// Perform an unaligned 64-bit store @@ -91,7 +91,7 @@ void unaligned_store_u64a(void *ptr, u64a val) { struct unaligned { u64a u; } PACKED__MAY_ALIAS; // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; - uptr->u = val; + uptr->u = val; //NOLINT (clang-analyzer-cplusplus.NewDelete) } #undef PACKED__MAY_ALIAS From e36203c3238d460064eba5b06606605b958904e6 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Fri, 31 May 2024 09:47:45 +0300 Subject: [PATCH 6/8] remove comment --- unit/hyperscan/expr_info.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/unit/hyperscan/expr_info.cpp b/unit/hyperscan/expr_info.cpp index 647714e2..58f4a9ab 100644 --- a/unit/hyperscan/expr_info.cpp +++ b/unit/hyperscan/expr_info.cpp @@ -89,7 +89,6 @@ ostream& operator<<(ostream &os, const hs_expr_ext &ext) { os << ", "; } os << "hamming_distance=" << ext.hamming_distance; - //first = false; } return os; } From 00a5ff1c678d98af922621c275310a5e13f5e95f Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Fri, 31 May 2024 10:24:44 +0300 Subject: [PATCH 7/8] clang-analyzer-core.uninitialized.UndefReturn --- src/util/ue2_graph.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/util/ue2_graph.h b/src/util/ue2_graph.h index 9d9f22d1..c3bf7755 100644 --- a/src/util/ue2_graph.h +++ b/src/util/ue2_graph.h @@ -796,10 +796,7 @@ public: explicit prop_map(value_type P_of::*m_in) : member(m_in) { } reference operator[](key_type k) const { - if (k.raw() == nullptr || &(k.raw()->props) == nullptr) { - throw std::invalid_argument("Invalid key"); - } - return k.raw()->props.*member; + return k.raw()->props.*member; //NOLINT (clang-analyzer-core.uninitialized.UndefReturn) } reference operator()(key_type k) const { return (*this)[k]; } From 9987ecd4a0cbd3fe54a24705e0cfb95db069598b Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Fri, 31 May 2024 10:34:55 +0300 Subject: [PATCH 8/8] clang-analyzer-cplusplus.Move --- util/ng_corpus_generator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/ng_corpus_generator.cpp b/util/ng_corpus_generator.cpp index 69e7c4ef..e0197b56 100644 --- a/util/ng_corpus_generator.cpp +++ b/util/ng_corpus_generator.cpp @@ -185,8 +185,8 @@ void findPaths(const NGHolder &g, CorpusProperties &cProps, continue; } - if (p && !contains(one_way_in, v) && - has_greater_than(p->begin(), p->end(), v, cycleLimit)) { + if (!contains(one_way_in, v) && + has_greater_than(p->begin(), p->end(), v, cycleLimit)) { //NOLINT (clang-analyzer-cplusplus.Move) // Note that vertices that only have one predecessor don't need // their cycle limit checked, as their predecessors will have // the same count.