Fix/Suppress remaining Cppcheck warnings (#291)

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
This commit is contained in:
Konstantinos Margaritis
2024-05-27 12:23:02 +03:00
committed by GitHub
parent a8e43a4c0b
commit 02fc8e3b1c
78 changed files with 204 additions and 131 deletions

View 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;

View 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) {

View 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());
}
}

View 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);

View 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);

View 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) {

View 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;
}

View 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);

View 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;

View 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

View 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);
}

View 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;
}

View 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) {

View 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

View 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;

View 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();

View 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;

View 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 <>

View 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;
}

View 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);