From a1fbe8466072ebdd1986e9bdd6d4e3d46c1c7720 Mon Sep 17 00:00:00 2001 From: Konstantinos Margaritis Date: Sun, 12 May 2024 18:40:51 +0300 Subject: [PATCH 1/2] Fix marked as false positive knownConditionTrueFalse cppcheck warnings std::make_shared<> does not return null, it throws std::bad_alloc. --- src/nfa/goughcompile.cpp | 8 -------- src/nfagraph/ng_som.cpp | 8 -------- src/nfagraph/ng_violet.cpp | 19 ++----------------- src/rose/rose_build_convert.cpp | 5 +---- 4 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/nfa/goughcompile.cpp b/src/nfa/goughcompile.cpp index 98031617..a23d570a 100644 --- a/src/nfa/goughcompile.cpp +++ b/src/nfa/goughcompile.cpp @@ -206,10 +206,6 @@ void makeCFG_top_edge(GoughGraph &cfg, const vector &vertices, assert(contains(src_slots, slot_id)); shared_ptr vmin = make_shared(); - if (!vmin) { - assert(0); - throw std::bad_alloc(); - } cfg[e].vars.emplace_back(vmin); final_var = vmin.get(); @@ -321,10 +317,6 @@ void makeCFG_edge(GoughGraph &cfg, const map &som_creators, DEBUG_PRINTF("bypassing min on join %u\n", slot_id); } else { shared_ptr vmin = make_shared(); - if (!vmin) { - assert(0); - throw std::bad_alloc(); - } cfg[e].vars.emplace_back(vmin); final_var = vmin.get(); diff --git a/src/nfagraph/ng_som.cpp b/src/nfagraph/ng_som.cpp index ee5a8f18..518b6ebc 100644 --- a/src/nfagraph/ng_som.cpp +++ b/src/nfagraph/ng_som.cpp @@ -2445,10 +2445,6 @@ static bool doLitHaigSom(NG &ng, const NGHolder &g, som_type som) { ue2_literal lit; shared_ptr rhs = make_shared(); - if (!rhs) { - assert(0); - throw std::bad_alloc(); - } if (!ng.cc.grey.allowLitHaig) { return false; } @@ -2513,10 +2509,6 @@ bool doHaigLitHaigSom(NG &ng, NGHolder &g, ue2_literal lit; shared_ptr rhs = make_shared(); shared_ptr lhs = make_shared(); - if (!rhs || !lhs) { - assert(0); - throw std::bad_alloc(); - } if (!splitOffBestLiteral(g, regions, &lit, &*lhs, &*rhs, ng.cc)) { return false; diff --git a/src/nfagraph/ng_violet.cpp b/src/nfagraph/ng_violet.cpp index 86cdf5ae..05a44117 100644 --- a/src/nfagraph/ng_violet.cpp +++ b/src/nfagraph/ng_violet.cpp @@ -1035,11 +1035,6 @@ bool splitRoseEdge(const NGHolder &base_graph, RoseInGraph &vg, shared_ptr lhs = make_shared(); shared_ptr rhs = make_shared(); - if (!lhs || !rhs) { - assert(0); - throw std::bad_alloc(); - } - unordered_map lhs_map; unordered_map rhs_map; @@ -1233,10 +1228,6 @@ void splitEdgesByCut(const NGHolder &h, RoseInGraph &vg, DEBUG_PRINTF("splitting on pivot %zu\n", h[pivot].index); unordered_map temp_map; shared_ptr new_lhs = make_shared(); - if (!new_lhs) { - assert(0); - throw std::bad_alloc(); - } splitLHS(h, pivot, new_lhs.get(), &temp_map); /* want to cut off paths to pivot from things other than the pivot - @@ -1318,10 +1309,7 @@ void splitEdgesByCut(const NGHolder &h, RoseInGraph &vg, if (!contains(done_rhs, adj)) { unordered_map temp_map; shared_ptr new_rhs = make_shared(); - if (!new_rhs) { - assert(0); - throw std::bad_alloc(); - } + splitRHS(h, adj, new_rhs.get(), &temp_map); remove_edge(new_rhs->start, new_rhs->accept, *new_rhs); remove_edge(new_rhs->start, new_rhs->acceptEod, *new_rhs); @@ -2293,10 +2281,7 @@ void splitEdgesForSuffix(const NGHolder &base_graph, RoseInGraph &vg, assert(!splitters.empty()); shared_ptr lhs = make_shared(); - if (!lhs) { - assert(0); - throw bad_alloc(); - } + unordered_map v_map; cloneHolder(*lhs, base_graph, &v_map); lhs->kind = NFA_INFIX; diff --git a/src/rose/rose_build_convert.cpp b/src/rose/rose_build_convert.cpp index c89c6ddd..9f1e563e 100644 --- a/src/rose/rose_build_convert.cpp +++ b/src/rose/rose_build_convert.cpp @@ -561,10 +561,7 @@ bool handleMixedPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v, DEBUG_PRINTF("woot?\n"); shared_ptr h_new = make_shared(); - if (!h_new) { - assert(0); - throw std::bad_alloc(); - } + unordered_map rhs_map; vector exits_vec; insert(&exits_vec, exits_vec.end(), exits); From 879cc0a18349ea64560af1aa07f4e13f7c1fb03d Mon Sep 17 00:00:00 2001 From: Konstantinos Margaritis Date: Sun, 12 May 2024 20:25:29 +0300 Subject: [PATCH 2/2] nodes is never empty at this stage, emplace_back() is called just previously --- src/nfagraph/ng_puff.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/nfagraph/ng_puff.cpp b/src/nfagraph/ng_puff.cpp index 8f130eaa..ab43d1c6 100644 --- a/src/nfagraph/ng_puff.cpp +++ b/src/nfagraph/ng_puff.cpp @@ -358,9 +358,7 @@ bool doComponent(RoseBuild &rose, ReportManager &rm, NGHolder &g, NFAVertex a, // single report ID on a vertex if (is_match_vertex(a, g)) { DEBUG_PRINTF("stop puffing due to vertex that leads to accept\n"); - if (!nodes.empty()) { - nodes.pop_back(); - } + nodes.pop_back(); break; } }