Skip to content

Commit da02a8e

Browse files
committed
feat: Use _pv destroy functions to satisfy UBSAN checks
1 parent c705a49 commit da02a8e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/rinterface.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424

2525
#include "rinterface.h"
2626

27+
// This is a variant of IGRAPH_FINALLY that satisfies UBSAN checks.
28+
#define IGRAPH_FINALLY_PV(func, ptr) \
29+
do { \
30+
/* the following branch makes the compiler check the compatibility of \
31+
* func and ptr to detect cases when we are accidentally invoking an \
32+
* incorrect destructor function with the pointer */ \
33+
if (0) { func(ptr); } \
34+
IGRAPH_FINALLY_REAL((igraph_finally_func_t*)(func##_pv), (ptr)); \
35+
} while (0)
36+
37+
void igraph_vector_int_destroy_pv(void* pv_ptr) {
38+
igraph_vector_int_destroy((igraph_vector_int_t*) pv_ptr);
39+
}
40+
2741
/***********************************************/
2842
/* THE REST IS GENERATED BY stimulus */
2943
/***********************************************/
@@ -11272,7 +11286,7 @@ SEXP R_igraph_eulerian_cycle(SEXP graph) {
1127211286
if (0 != igraph_vector_int_init(&c_vertex_res, 0)) {
1127311287
igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM);
1127411288
}
11275-
IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_res);
11289+
IGRAPH_FINALLY_PV(igraph_vector_int_destroy, &c_vertex_res);
1127611290
/* Call igraph */
1127711291
IGRAPH_R_CHECK(igraph_eulerian_cycle(&c_graph, &c_edge_res, &c_vertex_res));
1127811292

0 commit comments

Comments
 (0)