From cc1528d563854eff25d6c395d6851689dd0d1ed7 Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 11:03:17 +0000 Subject: [PATCH 1/7] Clang-Tidy: cppcoreguidelines-narrowing-conversions warning and fix --- .clang-tidy | 1 - src/cpp_common/undirectedHasCostBG.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index aa9f598740..b06ea19dc6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,6 @@ Checks: > -cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-macro-usage, - -cppcoreguidelines-narrowing-conversions, -cppcoreguidelines-no-malloc, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index b529c57b8f..1634a44a96 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -166,7 +166,7 @@ void UndirectedHasCostBG::insert_vertex(int64_t id) { try { if (has_vertex(id)) return; - auto v = add_vertex(m_id_to_V.size(), m_graph); + auto v = add_vertex(static_cast(m_id_to_V.size()), m_graph); m_id_to_V.insert(std::make_pair(id, v)); m_V_to_id.insert(std::make_pair(v, id)); } catch (...) { From 6a2c3e47e5acaeb0b607a64a273d7580d37b6572 Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 11:34:09 +0000 Subject: [PATCH 2/7] Clang-Tidy: cppcoreguidelines-narrowing-conversions warning and fix adding assert --- src/cpp_common/undirectedHasCostBG.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index 1634a44a96..58c296a448 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -32,7 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include - +#include +#include #include "c_types/iid_t_rt.h" #include "cpp_common/coordinate_t.hpp" #include "cpp_common/interruption.hpp" @@ -166,6 +167,7 @@ void UndirectedHasCostBG::insert_vertex(int64_t id) { try { if (has_vertex(id)) return; + assert(m_id_to_V.size() <= static_cast(std::numeric_limits::max())); auto v = add_vertex(static_cast(m_id_to_V.size()), m_graph); m_id_to_V.insert(std::make_pair(id, v)); m_V_to_id.insert(std::make_pair(v, id)); From 8441876a22d3fa163295c9a2ecce24f574a6cba3 Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 11:40:38 +0000 Subject: [PATCH 3/7] Clang-Tidy: cppcoreguidelines-narrowing-conversions warning and fix --- src/cpp_common/undirectedHasCostBG.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index 58c296a448..baf9e80412 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -#include #include #include #include "c_types/iid_t_rt.h" From e85cc2354c360ffe211f21d8cb8bbe8ac2f37c6a Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 11:47:13 +0000 Subject: [PATCH 4/7] Clang-Tidy: cppcoreguidelines-narrowing-conversions warning and fix --- src/cpp_common/undirectedHasCostBG.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index baf9e80412..2d0cc68bdd 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -#include +#include #include #include "c_types/iid_t_rt.h" #include "cpp_common/coordinate_t.hpp" From 80f4d0a8c4a189cadc24c6180637dab63c261e91 Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 12:05:34 +0000 Subject: [PATCH 5/7] Added an runtime check instead of assert --- src/cpp_common/undirectedHasCostBG.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index 2d0cc68bdd..eefcb0fd2b 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "cpp_common/undirectedHasCostBG.hpp" - +#include #include #include #include @@ -166,8 +166,13 @@ void UndirectedHasCostBG::insert_vertex(int64_t id) { try { if (has_vertex(id)) return; - assert(m_id_to_V.size() <= static_cast(std::numeric_limits::max())); - auto v = add_vertex(static_cast(m_id_to_V.size()), m_graph); + const auto vertex_count = m_id_to_V.size(); + + if (vertex_count > static_cast(std::numeric_limits::max())) { + throw std::overflow_error("vertex index overflow"); + } + + auto v = add_vertex(static_cast(vertex_count), m_graph); m_id_to_V.insert(std::make_pair(id, v)); m_V_to_id.insert(std::make_pair(v, id)); } catch (...) { From 4b8cda721794a671194b6313684a0d1b7832690f Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Sun, 22 Mar 2026 12:13:48 +0000 Subject: [PATCH 6/7] Removing unused assert --- src/cpp_common/undirectedHasCostBG.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index eefcb0fd2b..c59cb5fdcc 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -#include #include #include "c_types/iid_t_rt.h" #include "cpp_common/coordinate_t.hpp" From 7b720613c5e6e51728e903fe65326897ed6dde20 Mon Sep 17 00:00:00 2001 From: Ritesh200422 Date: Mon, 23 Mar 2026 16:06:07 +0000 Subject: [PATCH 7/7] some safety check asper coderabbit --- src/cpp_common/undirectedHasCostBG.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cpp_common/undirectedHasCostBG.cpp b/src/cpp_common/undirectedHasCostBG.cpp index c59cb5fdcc..5fc3cd6258 100644 --- a/src/cpp_common/undirectedHasCostBG.cpp +++ b/src/cpp_common/undirectedHasCostBG.cpp @@ -166,12 +166,14 @@ UndirectedHasCostBG::insert_vertex(int64_t id) { try { if (has_vertex(id)) return; const auto vertex_count = m_id_to_V.size(); + const auto max_int = static_cast(std::numeric_limits::max()); - if (vertex_count > static_cast(std::numeric_limits::max())) { - throw std::overflow_error("vertex index overflow"); + if (vertex_count > max_int) { + throw std::overflow_error("vertex index exceeds int range"); } auto v = add_vertex(static_cast(vertex_count), m_graph); + m_id_to_V.insert(std::make_pair(id, v)); m_V_to_id.insert(std::make_pair(v, id)); } catch (...) {