diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index c4c93699..81402994 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -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; diff --git a/benchmarks/benchmarks.hpp b/benchmarks/benchmarks.hpp index 96874318..fb8698ed 100644 --- a/benchmarks/benchmarks.hpp +++ b/benchmarks/benchmarks.hpp @@ -61,7 +61,7 @@ public: std::vector buf; // Noodle - struct hs_scratch scratch; + struct hs_scratch scratch{}; ue2::bytecode_ptr nt; MicroBenchmark(char const *label_, size_t size_) diff --git a/cppcheck-suppression-list.txt b/cppcheck-suppression-list.txt new file mode 100644 index 00000000..aa7fedc6 --- /dev/null +++ b/cppcheck-suppression-list.txt @@ -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 diff --git a/src/fdr/fdr_compile_util.cpp b/src/fdr/fdr_compile_util.cpp index 350a0967..ff2275f0 100644 --- a/src/fdr/fdr_compile_util.cpp +++ b/src/fdr/fdr_compile_util.cpp @@ -39,6 +39,7 @@ namespace ue2 { size_t maxLen(const vector &lits) { size_t rv = 0; for (const auto &lit : lits) { + // cppcheck-suppress useStlAlgorithm rv = max(rv, lit.s.size()); } return rv; diff --git a/src/fdr/fdr_dump.cpp b/src/fdr/fdr_dump.cpp index 1390c4f2..7daf345c 100644 --- a/src/fdr/fdr_dump.cpp +++ b/src/fdr/fdr_dump.cpp @@ -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++) { diff --git a/src/hwlm/hwlm_build.cpp b/src/hwlm/hwlm_build.cpp index bb83849b..e381fc47 100644 --- a/src/hwlm/hwlm_build.cpp +++ b/src/hwlm/hwlm_build.cpp @@ -93,6 +93,7 @@ void dumpLits(UNUSED const vector &lits) { // Called by an assertion. static bool everyoneHasGroups(const vector &lits) { + // cppcheck-suppress useStlAlgorithm for (const auto &lit : lits) { if (!lit.groups) { return false; diff --git a/src/nfa/goughcompile.cpp b/src/nfa/goughcompile.cpp index 4765cd03..322b87ab 100644 --- a/src/nfa/goughcompile.cpp +++ b/src/nfa/goughcompile.cpp @@ -595,6 +595,7 @@ void GoughSSAVarNew::generate(vector *out) const { #ifndef NDEBUG template 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; diff --git a/src/nfa/goughcompile_dump.cpp b/src/nfa/goughcompile_dump.cpp index ca94b69f..649310c6 100644 --- a/src/nfa/goughcompile_dump.cpp +++ b/src/nfa/goughcompile_dump.cpp @@ -145,6 +145,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base, fprintf(f, "\tuses:"); vector 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 used_id; for (const GoughSSAVar *var : used) { + // cppcheck-suppress useStlAlgorithm used_id.emplace_back(var->slot); } for (const u32 &id : used_id) { diff --git a/src/nfa/goughcompile_reg.cpp b/src/nfa/goughcompile_reg.cpp index 92131306..6668ddbd 100644 --- a/src/nfa/goughcompile_reg.cpp +++ b/src/nfa/goughcompile_reg.cpp @@ -50,8 +50,8 @@ namespace ue2 { template void emplace_back_all_raw(vector *out, const vector &in) { - // cppcheck-suppress useStlAlgorithm for (const auto &var : in) { + // cppcheck-suppress useStlAlgorithm out->emplace_back(var.get()); } } diff --git a/src/nfa/goughdump.cpp b/src/nfa/goughdump.cpp index 8717d06a..ee2e873d 100644 --- a/src/nfa/goughdump.cpp +++ b/src/nfa/goughdump.cpp @@ -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); diff --git a/src/nfa/lbr_common_impl.h b/src/nfa/lbr_common_impl.h index 5ae35431..4f530e6d 100644 --- a/src/nfa/lbr_common_impl.h +++ b/src/nfa/lbr_common_impl.h @@ -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); diff --git a/src/nfa/limex_common_impl.h b/src/nfa/limex_common_impl.h index 48661871..2b0b3699 100644 --- a/src/nfa/limex_common_impl.h +++ b/src/nfa/limex_common_impl.h @@ -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) { diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index 5b32e910..304116a8 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -140,6 +140,7 @@ reindexByStateId(const unordered_map &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> &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; } diff --git a/src/nfa/limex_exceptional.h b/src/nfa/limex_exceptional.h index f472aee4..2488787c 100644 --- a/src/nfa/limex_exceptional.h +++ b/src/nfa/limex_exceptional.h @@ -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); diff --git a/src/nfa/mcclellancompile_util.cpp b/src/nfa/mcclellancompile_util.cpp index 44831b3d..59ec005c 100644 --- a/src/nfa/mcclellancompile_util.cpp +++ b/src/nfa/mcclellancompile_util.cpp @@ -210,6 +210,7 @@ set 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; diff --git a/src/nfa/mcclellandump.cpp b/src/nfa/mcclellandump.cpp index 071dd85b..475d3eba 100644 --- a/src/nfa/mcclellandump.cpp +++ b/src/nfa/mcclellandump.cpp @@ -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 diff --git a/src/nfa/mcsheng_dump.cpp b/src/nfa/mcsheng_dump.cpp index 352a9005..4a2a2129 100644 --- a/src/nfa/mcsheng_dump.cpp +++ b/src/nfa/mcsheng_dump.cpp @@ -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); } diff --git a/src/nfa/mpvcompile.cpp b/src/nfa/mpvcompile.cpp index 7c06da9d..7071b6ce 100644 --- a/src/nfa/mpvcompile.cpp +++ b/src/nfa/mpvcompile.cpp @@ -105,6 +105,7 @@ void writeSentinel(mpv_puffette *out) { static void writeDeadPoint(mpv_kilopuff *out, const vector &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 &counters, u32 i) { for (const auto &counter : counters) { + // cppcheck-suppress useStlAlgorithm if (i >= counter.kilo_begin && i < counter.kilo_end) { return counter; } diff --git a/src/nfa/nfa_build_util.cpp b/src/nfa/nfa_build_util.cpp index 86eb1510..eed33c97 100644 --- a/src/nfa/nfa_build_util.cpp +++ b/src/nfa/nfa_build_util.cpp @@ -138,7 +138,7 @@ template static string getDescriptionLimEx(const NFA *nfa) { const typename NFATraits::implNFA_t *limex = - (const typename NFATraits::implNFA_t *)getImplNfa(nfa); + reinterpret_cast::implNFA_t *>(getImplNfa(nfa)); ostringstream oss; oss << NFATraits::name << "/" << limex->exceptionCount; if (limex->repeatCount) { diff --git a/src/nfa/nfa_dump_internal.cpp b/src/nfa/nfa_dump_internal.cpp index 474db9b8..4ce2a797 100644 --- a/src/nfa/nfa_dump_internal.cpp +++ b/src/nfa/nfa_dump_internal.cpp @@ -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(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(c1), static_cast(c2), isprint(c1) ? c1 : '?', isprint(c2) ? c2 : '?'); } - fprintf(f, "offset %hhd\n", nfa->rAccelOffset); + fprintf(f, "offset %hhu\n", nfa->rAccelOffset); } } // namespace ue2 diff --git a/src/nfa/rdfa.cpp b/src/nfa/rdfa.cpp index ae857b6a..278816d0 100644 --- a/src/nfa/rdfa.cpp +++ b/src/nfa/rdfa.cpp @@ -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; diff --git a/src/nfa/rdfa.h b/src/nfa/rdfa.h index 6b994e4f..01910c28 100644 --- a/src/nfa/rdfa.h +++ b/src/nfa/rdfa.h @@ -76,7 +76,7 @@ struct raw_dfa { u16 alpha_size = 0; /* including special symbols */ /* mapping from input symbol --> equiv class id */ - std::array alpha_remap; + std::array alpha_remap{}; explicit raw_dfa(nfa_kind k) : kind(k) {} virtual ~raw_dfa(); diff --git a/src/nfa/rdfa_merge.cpp b/src/nfa/rdfa_merge.cpp index 588f94e3..b0652115 100644 --- a/src/nfa/rdfa_merge.cpp +++ b/src/nfa/rdfa_merge.cpp @@ -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 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; diff --git a/src/nfa/shengdump.cpp b/src/nfa/shengdump.cpp index c0c4a56f..2c350bb0 100644 --- a/src/nfa/shengdump.cpp +++ b/src/nfa/shengdump.cpp @@ -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 static void describeNode(UNUSED const NFA *n, UNUSED const T *s, UNUSED u16 i, - UNUSED FILE *f) { + UNUSED FILE *f) { // cppcheck-suppress constParameterPointer } template <> diff --git a/src/nfa/tamarama.c b/src/nfa/tamarama.c index 43480f06..cfb78c7e 100644 --- a/src/nfa/tamarama.c +++ b/src/nfa/tamarama.c @@ -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; } diff --git a/src/nfa/tamaramacompile.cpp b/src/nfa/tamaramacompile.cpp index 5ca41604..7dc3ebba 100644 --- a/src/nfa/tamaramacompile.cpp +++ b/src/nfa/tamaramacompile.cpp @@ -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); diff --git a/src/nfagraph/ng_equivalence.cpp b/src/nfagraph/ng_equivalence.cpp index 5b9e5a49..923163bd 100644 --- a/src/nfagraph/ng_equivalence.cpp +++ b/src/nfagraph/ng_equivalence.cpp @@ -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; diff --git a/src/nfagraph/ng_holder.h b/src/nfagraph/ng_holder.h index 36cf6244..b2d36bcc 100644 --- a/src/nfagraph/ng_holder.h +++ b/src/nfagraph/ng_holder.h @@ -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. diff --git a/src/nfagraph/ng_limex.cpp b/src/nfagraph/ng_limex.cpp index dad3cb47..e7c28b18 100644 --- a/src/nfagraph/ng_limex.cpp +++ b/src/nfagraph/ng_limex.cpp @@ -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 &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)) { diff --git a/src/nfagraph/ng_limex_accel.cpp b/src/nfagraph/ng_limex_accel.cpp index 0cf6006d..21e7fa05 100644 --- a/src/nfagraph/ng_limex_accel.cpp +++ b/src/nfagraph/ng_limex_accel.cpp @@ -463,6 +463,7 @@ void blowoutPathsLessStrictSegment(vector > &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) { diff --git a/src/nfagraph/ng_literal_analysis.cpp b/src/nfagraph/ng_literal_analysis.cpp index bd9c3ab2..178f5aa3 100644 --- a/src/nfagraph/ng_literal_analysis.cpp +++ b/src/nfagraph/ng_literal_analysis.cpp @@ -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 add_reverse_edges_and_index(LitGraph &lg) { vector 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 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"); diff --git a/src/nfagraph/ng_literal_decorated.cpp b/src/nfagraph/ng_literal_decorated.cpp index 7fa2416a..85fbc081 100644 --- a/src/nfagraph/ng_literal_decorated.cpp +++ b/src/nfagraph/ng_literal_decorated.cpp @@ -131,6 +131,7 @@ bool findPaths(const NGHolder &g, vector &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; diff --git a/src/nfagraph/ng_mcclellan.cpp b/src/nfagraph/ng_mcclellan.cpp index 1e4b743f..3b6c0760 100644 --- a/src/nfagraph/ng_mcclellan.cpp +++ b/src/nfagraph/ng_mcclellan.cpp @@ -129,6 +129,7 @@ void calculateAlphabet(const NGHolder &g, array &alpha, static bool allExternalReports(const ReportManager &rm, const flat_set &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 &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); diff --git a/src/nfagraph/ng_misc_opt.cpp b/src/nfagraph/ng_misc_opt.cpp index fa7496c5..1eb84233 100644 --- a/src/nfagraph/ng_misc_opt.cpp +++ b/src/nfagraph/ng_misc_opt.cpp @@ -482,6 +482,7 @@ vector 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; diff --git a/src/nfagraph/ng_region.h b/src/nfagraph/ng_region.h index 9f53a0e4..e19c94ba 100644 --- a/src/nfagraph/ng_region.h +++ b/src/nfagraph/ng_region.h @@ -115,6 +115,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v, const std::unordered_map ®ion_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 bool isRegionExit(const Graph &g, NFAVertex v, const std::unordered_map ®ion_map) { + // cppcheck-suppress useStlAlgorithm for (auto w : adjacent_vertices_range(v, g)) { if (!inSameRegion(g, v, w, region_map)) { return true; diff --git a/src/nfagraph/ng_repeat.cpp b/src/nfagraph/ng_repeat.cpp index 4c5341c8..b94e22a1 100644 --- a/src/nfagraph/ng_repeat.cpp +++ b/src/nfagraph/ng_repeat.cpp @@ -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); diff --git a/src/nfagraph/ng_restructuring.cpp b/src/nfagraph/ng_restructuring.cpp index 99f287db..a05f0f63 100644 --- a/src/nfagraph/ng_restructuring.cpp +++ b/src/nfagraph/ng_restructuring.cpp @@ -210,7 +210,6 @@ u32 countStates(const unordered_map &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); } } diff --git a/src/nfagraph/ng_util.cpp b/src/nfagraph/ng_util.cpp index 605f669c..90b49929 100644 --- a/src/nfagraph/ng_util.cpp +++ b/src/nfagraph/ng_util.cpp @@ -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; diff --git a/src/parser/Parser.rl b/src/parser/Parser.rl index 232b0218..2ab9483a 100644 --- a/src/parser/Parser.rl +++ b/src/parser/Parser.rl @@ -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 diff --git a/src/parser/buildstate.cpp b/src/parser/buildstate.cpp index c243f626..871f1180 100644 --- a/src/parser/buildstate.cpp +++ b/src/parser/buildstate.cpp @@ -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 &lasts, + // cppcheck-suppress virtualCallInConstructor + virtual void connectRegions(const vector &lasts, const vector &firsts) override; /** \brief Wire the lasts of the main sequence to accepts. */ diff --git a/src/parser/control_verbs.rl b/src/parser/control_verbs.rl index 09b0bfd7..ca682da6 100644 --- a/src/parser/control_verbs.rl +++ b/src/parser/control_verbs.rl @@ -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 { diff --git a/src/parser/position_info.h b/src/parser/position_info.h index 4e64a280..e9a03870 100644 --- a/src/parser/position_info.h +++ b/src/parser/position_info.h @@ -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 { diff --git a/src/parser/prefilter.cpp b/src/parser/prefilter.cpp index f69362e4..3836a6fe 100644 --- a/src/parser/prefilter.cpp +++ b/src/parser/prefilter.cpp @@ -347,6 +347,7 @@ void prefilterTree(unique_ptr &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); diff --git a/src/rose/rose_build_add.cpp b/src/rose/rose_build_add.cpp index 78d13e3c..9eafc80d 100644 --- a/src/rose/rose_build_add.cpp +++ b/src/rose/rose_build_add.cpp @@ -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 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; } diff --git a/src/rose/rose_build_add_mask.cpp b/src/rose/rose_build_add_mask.cpp index abfc7178..5a1d44fa 100644 --- a/src/rose/rose_build_add_mask.cpp +++ b/src/rose/rose_build_add_mask.cpp @@ -188,7 +188,7 @@ bool expandFmlCandidates(const CharReach &cr, vector &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; diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index bb56c5bc..9c7bb6fd 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -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); diff --git a/src/rose/rose_build_compile.cpp b/src/rose/rose_build_compile.cpp index ed06aeb1..cf713c2f 100644 --- a/src/rose/rose_build_compile.cpp +++ b/src/rose/rose_build_compile.cpp @@ -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 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); diff --git a/src/rose/rose_build_dump.cpp b/src/rose/rose_build_dump.cpp index 7112910b..5c485255 100644 --- a/src/rose/rose_build_dump.cpp +++ b/src/rose/rose_build_dump.cpp @@ -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(n) - reinterpret_cast(t)), describe(*n).c_str(), n->nPositions, n->streamStateSize, n->length, diff --git a/src/rose/rose_build_exclusive.cpp b/src/rose/rose_build_exclusive.cpp index d8769026..0371a011 100644 --- a/src/rose/rose_build_exclusive.cpp +++ b/src/rose/rose_build_exclusive.cpp @@ -140,6 +140,7 @@ static bool isSuffix(const vector> &triggers1, const vector> &triggers2) { // literal suffix test + // cppcheck-suppress useStlAlgorithm for (const auto &lit1 : triggers1) { // cppcheck-suppress useStlAlgorithm for (const auto &lit2 : triggers2) { diff --git a/src/rose/rose_build_misc.cpp b/src/rose/rose_build_misc.cpp index a5225d3b..cab0fad6 100644 --- a/src/rose/rose_build_misc.cpp +++ b/src/rose/rose_build_misc.cpp @@ -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(), diff --git a/src/rose/rose_build_role_aliasing.cpp b/src/rose/rose_build_role_aliasing.cpp index a762520d..60ff8384 100644 --- a/src/rose/rose_build_role_aliasing.cpp +++ b/src/rose/rose_build_role_aliasing.cpp @@ -737,8 +737,8 @@ void pruneReportIfUnused(const RoseBuildImpl &build, shared_ptr 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; diff --git a/src/rose/rose_build_width.cpp b/src/rose/rose_build_width.cpp index e534859a..156e1d71 100644 --- a/src/rose/rose_build_width.cpp +++ b/src/rose/rose_build_width.cpp @@ -65,7 +65,7 @@ u32 findMinWidth(const RoseBuildImpl &tbi, enum rose_literal_table table) { const RoseGraph &g = tbi.g; vector 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 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))); }; diff --git a/src/som/slot_manager_dump.cpp b/src/som/slot_manager_dump.cpp index 4ed5cef0..107e24ee 100644 --- a/src/som/slot_manager_dump.cpp +++ b/src/som/slot_manager_dump.cpp @@ -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); } diff --git a/src/util/arch/arm/simd_utils.h b/src/util/arch/arm/simd_utils.h index 7f8539b0..e1b60558 100644 --- a/src/util/arch/arm/simd_utils.h +++ b/src/util/arch/arm/simd_utils.h @@ -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); } diff --git a/src/util/arch/ppc64el/simd_utils.h b/src/util/arch/ppc64el/simd_utils.h index 15446e87..9b6f7539 100644 --- a/src/util/arch/ppc64el/simd_utils.h +++ b/src/util/arch/ppc64el/simd_utils.h @@ -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); } diff --git a/src/util/depth.h b/src/util/depth.h index 5305c6f1..07d6ee03 100644 --- a/src/util/depth.h +++ b/src/util/depth.h @@ -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(); } diff --git a/src/util/dump_charclass.cpp b/src/util/dump_charclass.cpp index 2243fcbd..56466f1e 100644 --- a/src/util/dump_charclass.cpp +++ b/src/util/dump_charclass.cpp @@ -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() << ']'; diff --git a/src/util/flat_containers.h b/src/util/flat_containers.h index 9ba7e232..b3dce4fa 100644 --- a/src/util/flat_containers.h +++ b/src/util/flat_containers.h @@ -62,6 +62,7 @@ private: public: template + // cppcheck-suppress noExplicitConstructor iter_wrapper(iter_wrapper other, typename std::enable_if::value>::type * = nullptr) diff --git a/src/util/graph_undirected.h b/src/util/graph_undirected.h index 50717284..7ecd39af 100644 --- a/src/util/graph_undirected.h +++ b/src/util/graph_undirected.h @@ -146,7 +146,7 @@ public: adj_edge_iterator, 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 { - const base_type *g; + const base_type *g = nullptr; typename Traits::edge_iterator it; public: edge_iterator() = default; diff --git a/src/util/insertion_ordered.h b/src/util/insertion_ordered.h index 7121ab2b..8ba15dcd 100644 --- a/src/util/insertion_ordered.h +++ b/src/util/insertion_ordered.h @@ -64,6 +64,7 @@ public: template friend class iter_wrapper; template + // cppcheck-suppress noExplicitConstructor iter_wrapper(iter_wrapper other, typename std::enable_if::value>::type * = nullptr) diff --git a/src/util/partitioned_set.h b/src/util/partitioned_set.h index f6971263..30d015c0 100644 --- a/src/util/partitioned_set.h +++ b/src/util/partitioned_set.h @@ -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); diff --git a/src/util/supervector/arch/ppc64el/impl.cpp b/src/util/supervector/arch/ppc64el/impl.cpp index 3b2cfa6b..b2c69271 100644 --- a/src/util/supervector/arch/ppc64el/impl.cpp +++ b/src/util/supervector/arch/ppc64el/impl.cpp @@ -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(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(ptr))); } template <> diff --git a/src/util/uniform_ops.h b/src/util/uniform_ops.h index fddc2253..38e55efe 100644 --- a/src/util/uniform_ops.h +++ b/src/util/uniform_ops.h @@ -41,16 +41,16 @@ #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(a)) -#define load_u16(a) (*(reinterpret_cast(a)) -#define load_u32(a) (*(reinterpret_cast(a)) -#define load_u64a(a) (*(reinterpret_cast(a)) +#define load_u8(a) (*(reinterpret_cast(a))) +#define load_u16(a) (*(reinterpret_cast(a))) +#define load_u32(a) (*(reinterpret_cast(a))) +#define load_u64a(a) (*(reinterpret_cast(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)) @@ -68,31 +68,35 @@ #define loadu_u16(a) unaligned_load_u16(reinterpret_cast(a)) #define loadu_u32(a) unaligned_load_u32(reinterpret_cast(a)) #define loadu_u64a(a) unaligned_load_u64a(reinterpret_cast(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(ptr)) = (a); } while(0) #define store_u16(ptr, a) do { *(reinterpret_cast(ptr)) = (a); } while(0) #define store_u32(ptr, a) do { *(reinterpret_cast(ptr)) = (a); } while(0) #define store_u64a(ptr, a) do { *(reinterpret_cast(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(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) diff --git a/tools/hsbench/engine_chimera.h b/tools/hsbench/engine_chimera.h index 52ec1179..642ce75c 100644 --- a/tools/hsbench/engine_chimera.h +++ b/tools/hsbench/engine_chimera.h @@ -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 makeContext() const override; diff --git a/tools/hsbench/engine_hyperscan.h b/tools/hsbench/engine_hyperscan.h index ccbc2fa8..fa517459 100644 --- a/tools/hsbench/engine_hyperscan.h +++ b/tools/hsbench/engine_hyperscan.h @@ -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 makeContext() const override; diff --git a/tools/hsbench/engine_pcre.h b/tools/hsbench/engine_pcre.h index 7ae9147f..8f87fabb 100644 --- a/tools/hsbench/engine_pcre.h +++ b/tools/hsbench/engine_pcre.h @@ -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> dbs_in, CompilePCREStats cs, int capture_cnt_in); - ~EnginePCRE(); + virtual ~EnginePCRE() override; std::unique_ptr makeContext() const override; diff --git a/tools/hsbench/main.cpp b/tools/hsbench/main.cpp index 857d5cad..d0533ad6 100644 --- a/tools/hsbench/main.cpp +++ b/tools/hsbench/main.cpp @@ -759,11 +759,9 @@ void displayResults(const vector> &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> &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> &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); diff --git a/tools/hsdump/main.cpp b/tools/hsdump/main.cpp index 6c8464b6..0364b93a 100644 --- a/tools/hsdump/main.cpp +++ b/tools/hsdump/main.cpp @@ -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 &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; diff --git a/unit/hyperscan/test_util.cpp b/unit/hyperscan/test_util.cpp index 09040bf9..0477e966 100644 --- a/unit/hyperscan/test_util.cpp +++ b/unit/hyperscan/test_util.cpp @@ -192,6 +192,7 @@ void *count_malloc(size_t n) { *(reinterpret_cast(pp)) = n; void *p = static_cast(pp) + 16; + // cppcheck-suppress memleak return p; } @@ -218,6 +219,7 @@ void *count_malloc_b(size_t n) { *(reinterpret_cast(pp)) = n; void *p = static_cast(pp) + 32; + // cppcheck-suppress memleak return p; } diff --git a/unit/internal/charreach.cpp b/unit/internal/charreach.cpp index 377641d8..c44cfe52 100644 --- a/unit/internal/charreach.cpp +++ b/unit/internal/charreach.cpp @@ -98,7 +98,6 @@ TEST(ng_charreach, assignment) { cr2 = cr; ASSERT_EQ(cr.count(), cr2.count()); - ASSERT_TRUE(cr == cr2); } TEST(ng_charreach, flip) { diff --git a/unit/internal/fdr.cpp b/unit/internal/fdr.cpp index bc954770..3411064b 100644 --- a/unit/internal/fdr.cpp +++ b/unit/internal/fdr.cpp @@ -138,7 +138,7 @@ vector getValidFdrEngines() { static -bytecode_ptr buildFDREngineHinted(std::vector &lits, +bytecode_ptr buildFDREngineHinted(const std::vector &lits, bool make_small, u32 hint, const target_t &target, const Grey &grey) { @@ -151,7 +151,7 @@ bytecode_ptr buildFDREngineHinted(std::vector &lits, } static -bytecode_ptr buildFDREngine(std::vector &lits, +bytecode_ptr buildFDREngine(const std::vector &lits, bool make_small, const target_t &target, const Grey &grey) { auto proto = fdrBuildProto(HWLM_ENGINE_FDR, lits, make_small, target, grey); diff --git a/unit/internal/fdr_flood.cpp b/unit/internal/fdr_flood.cpp index a3b0cc96..dbfefb00 100644 --- a/unit/internal/fdr_flood.cpp +++ b/unit/internal/fdr_flood.cpp @@ -133,7 +133,7 @@ static vector getValidFdrEngines() { } static -bytecode_ptr buildFDREngineHinted(std::vector &lits, +bytecode_ptr buildFDREngineHinted(const std::vector &lits, bool make_small, u32 hint, const target_t &target, const Grey &grey) { diff --git a/unit/internal/flat_map.cpp b/unit/internal/flat_map.cpp index 610c71e1..b5cc0f39 100644 --- a/unit/internal/flat_map.cpp +++ b/unit/internal/flat_map.cpp @@ -370,31 +370,24 @@ TEST(flat_map, get_allocator) { TEST(flat_map, compare_ops) { flat_map f1 = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}}; - flat_map f1_copy = f1; flat_map 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); } diff --git a/unit/internal/flat_set.cpp b/unit/internal/flat_set.cpp index 174a4771..e0c84ceb 100644 --- a/unit/internal/flat_set.cpp +++ b/unit/internal/flat_set.cpp @@ -340,31 +340,24 @@ TEST(flat_set, iter_interop) { TEST(flat_set, compare_ops) { flat_set f1 = {1, 2, 3, 4, 5}; - flat_set f1_copy = f1; flat_set 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); } diff --git a/unit/internal/multi_bit.cpp b/unit/internal/multi_bit.cpp index d017f8a5..0f324c12 100644 --- a/unit/internal/multi_bit.cpp +++ b/unit/internal/multi_bit.cpp @@ -55,11 +55,11 @@ public: } operator u8 *() { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } operator const u8 *() const { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } private: diff --git a/unit/internal/multi_bit_compress.cpp b/unit/internal/multi_bit_compress.cpp index 5c65d0a9..b1d5b784 100644 --- a/unit/internal/multi_bit_compress.cpp +++ b/unit/internal/multi_bit_compress.cpp @@ -94,11 +94,11 @@ public: } operator u8 *() { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } operator const u8 *() const { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } private: @@ -116,11 +116,11 @@ public: } operator u8 *() { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } operator const u8 *() const { assert(data); - return data.get() + 7; + return reinterpret_cast(data.get()) + 7; } private: diff --git a/unit/internal/repeat.cpp b/unit/internal/repeat.cpp index b1792e1c..73098f6d 100644 --- a/unit/internal/repeat.cpp +++ b/unit/internal/repeat.cpp @@ -66,6 +66,7 @@ ostream& operator<<(ostream &os, const RepeatInfo &info) { class RepeatTest : public TestWithParam { 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 > { 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; }; diff --git a/util/ng_corpus_generator.cpp b/util/ng_corpus_generator.cpp index e13abb67..cb195eaf 100644 --- a/util/ng_corpus_generator.cpp +++ b/util/ng_corpus_generator.cpp @@ -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 &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 &data) override;