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

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

View File

@@ -114,6 +114,7 @@ public:
nfa_kind kind; /* Role that this plays in Rose */
// cppcheck-suppress duplInheritedMember
static const size_t N_SPECIAL_VERTICES = N_SPECIALS;
public:
const vertex_descriptor start; //!< Anchored start vertex.

View File

@@ -106,6 +106,7 @@ bool sanityCheckGraph(const NGHolder &g,
return false;
}
u32 s = state_ids.at(v);
// cppcheck-suppress knownConditionTrueFalse
if (s != NO_STATE && !seen_states.insert(s).second) {
DEBUG_PRINTF("vertex %zu has dupe state %u\n", g[v].index, s);
return false;
@@ -392,8 +393,8 @@ void reusePredsAsStarts(const NGHolder &g, const map<u32, CharReach> &top_reach,
auto cands = [&g=g](const NFAVertex &u) {
return (hasSelfLoop(u, g));
};
const auto &u = unhandled_succ_tops | map_keys;
std::copy_if(begin(u), end(u), std::back_inserter(cand_starts), cands);
const auto &ust = unhandled_succ_tops | map_keys;
std::copy_if(begin(ust), end(ust), std::back_inserter(cand_starts), cands);
for (NFAVertex u : cand_starts) {
if (!contains(unhandled_succ_tops, u)) {

View File

@@ -463,6 +463,7 @@ void blowoutPathsLessStrictSegment(vector<vector<CharReach> > &paths) {
/* paths segments which are a superset of an earlier segment should never be
* picked as an acceleration segment -> to improve processing just replace
* with dot */
// cppcheck-suppress constVariableReference
for (auto &p : paths) {
for (auto it = p.begin(); it != p.end(); ++it) {
for (auto jt = next(it); jt != p.end(); ++jt) {

View File

@@ -360,8 +360,8 @@ u64a litUniqueness(const string &s) {
static
u64a litCountBits(const ue2_literal &lit) {
u64a n = 0;
// cppcheck-suppress useStlAlgorithm
for (const auto &c : lit) {
// cppcheck-suppress useStlAlgorithm
n += c.nocase ? 7 : 8;
}
return n;
@@ -491,8 +491,8 @@ vector<LitEdge> add_reverse_edges_and_index(LitGraph &lg) {
vector<LitEdge> fwd_edges;
fwd_edges.reserve(edge_count);
const auto &e = edges_range(lg);
std::copy(begin(e), end(e), std::back_inserter(fwd_edges));
const auto &er = edges_range(lg);
std::copy(begin(er), end(er), std::back_inserter(fwd_edges));
vector<LitEdge> rev_map(2 * edge_count);
@@ -881,6 +881,7 @@ bool literalIsWholeGraph(const NGHolder &g, const ue2_literal &lit) {
}
// Our last value for v should have only start states for predecessors.
// cppcheck-suppress useStlAlgorithm
for (auto u : inv_adjacent_vertices_range(v, g)) {
if (!is_any_start(u, g)) {
DEBUG_PRINTF("pred is not start\n");

View File

@@ -131,6 +131,7 @@ bool findPaths(const NGHolder &g, vector<Path> &paths) {
static
bool hasLargeDegreeVertex(const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (const auto &v : vertices_range(g)) {
if (is_special(v, g)) { // specials can have large degree
continue;

View File

@@ -129,6 +129,7 @@ void calculateAlphabet(const NGHolder &g, array<u16, ALPHABET_SIZE> &alpha,
static
bool allExternalReports(const ReportManager &rm,
const flat_set<ReportID> &reports) {
// cppcheck-suppress useStlAlgorithm
for (auto report_id : reports) {
if (!isExternalReport(rm.getReport(report_id))) {
return false;
@@ -327,6 +328,7 @@ void markToppableStarts(const NGHolder &g, const flat_set<NFAVertex> &unused,
continue;
}
for (const auto &trigger : triggers) {
// cppcheck-suppress useStlAlgorithm
if (triggerAllowed(g, v, triggers, trigger)) {
DEBUG_PRINTF("idx %zu is valid location for top\n", g[v].index);
out->set(g[v].index);

View File

@@ -482,6 +482,7 @@ vector<CharReach> reduced_cr(const NGHolder &g,
static
bool anyOutSpecial(NFAVertex v, const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (is_special(w, g) && w != v) {
return true;

View File

@@ -115,6 +115,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v,
const std::unordered_map<NFAVertex, u32> &region_map) {
// Note that some graph types do not have inv_adjacent_vertices, so we must
// use in_edges here.
// cppcheck-suppress useStlAlgorithm
for (const auto &e : in_edges_range(v, g)) {
if (!inSameRegion(g, v, source(e, g), region_map)) {
return true;
@@ -128,6 +129,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v,
template <class Graph>
bool isRegionExit(const Graph &g, NFAVertex v,
const std::unordered_map<NFAVertex, u32> &region_map) {
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (!inSameRegion(g, v, w, region_map)) {
return true;

View File

@@ -2181,6 +2181,7 @@ bool hasOverlappingRepeats(UNUSED const NGHolder &g,
DEBUG_PRINTF("already seen pos %zu\n", g[br.pos_trigger].index);
return true;
}
// cppcheck-suppress useStlAlgorithm
for (auto v : br.tug_triggers) {
if (contains(involved, v)) {
DEBUG_PRINTF("already seen tug %zu\n", g[v].index);

View File

@@ -210,7 +210,6 @@ u32 countStates(const unordered_map<NFAVertex, u32> &state_ids) {
u32 max_state = 0;
for (const auto &m : state_ids) {
if (m.second != NO_STATE) {
// cppcheck-suppress useStlAlgorithm
max_state = max(m.second, max_state);
}
}

View File

@@ -776,12 +776,14 @@ bool allMatchStatesHaveReports(const NGHolder &g) {
bool isCorrectlyTopped(const NGHolder &g) {
if (is_triggered(g)) {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : out_edges_range(g.start, g)) {
if (g[e].tops.empty() != (target(e, g) == g.startDs)) {
return false;
}
}
} else {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : out_edges_range(g.start, g)) {
if (!g[e].tops.empty()) {
return false;