Skip to content

Commit 80f4d0a

Browse files
committed
Added an runtime check instead of assert
1 parent e85cc23 commit 80f4d0a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/cpp_common/undirectedHasCostBG.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2626
********************************************************************PGR-GNU*/
2727

2828
#include "cpp_common/undirectedHasCostBG.hpp"
29-
29+
#include <stdexcept>
3030
#include <utility>
3131
#include <vector>
3232
#include <deque>
@@ -166,8 +166,13 @@ void
166166
UndirectedHasCostBG::insert_vertex(int64_t id) {
167167
try {
168168
if (has_vertex(id)) return;
169-
assert(m_id_to_V.size() <= static_cast<size_t>(std::numeric_limits<int>::max()));
170-
auto v = add_vertex(static_cast<int>(m_id_to_V.size()), m_graph);
169+
const auto vertex_count = m_id_to_V.size();
170+
171+
if (vertex_count > static_cast<size_t>(std::numeric_limits<int>::max())) {
172+
throw std::overflow_error("vertex index overflow");
173+
}
174+
175+
auto v = add_vertex(static_cast<int>(vertex_count), m_graph);
171176
m_id_to_V.insert(std::make_pair(id, v));
172177
m_V_to_id.insert(std::make_pair(v, id));
173178
} catch (...) {

0 commit comments

Comments
 (0)