Skip to content

Commit

Permalink
feat: Use _pv destroy functions to satisfy UBSAN checks
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Dec 11, 2024
1 parent c705a49 commit da02a8e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/rinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@

#include "rinterface.h"

// This is a variant of IGRAPH_FINALLY that satisfies UBSAN checks.
#define IGRAPH_FINALLY_PV(func, ptr) \
do { \
/* the following branch makes the compiler check the compatibility of \
* func and ptr to detect cases when we are accidentally invoking an \
* incorrect destructor function with the pointer */ \
if (0) { func(ptr); } \
IGRAPH_FINALLY_REAL((igraph_finally_func_t*)(func##_pv), (ptr)); \
} while (0)

void igraph_vector_int_destroy_pv(void* pv_ptr) {
igraph_vector_int_destroy((igraph_vector_int_t*) pv_ptr);
}

/***********************************************/
/* THE REST IS GENERATED BY stimulus */
/***********************************************/
Expand Down Expand Up @@ -11272,7 +11286,7 @@ SEXP R_igraph_eulerian_cycle(SEXP graph) {
if (0 != igraph_vector_int_init(&c_vertex_res, 0)) {
igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM);
}
IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_res);
IGRAPH_FINALLY_PV(igraph_vector_int_destroy, &c_vertex_res);
/* Call igraph */
IGRAPH_R_CHECK(igraph_eulerian_cycle(&c_graph, &c_edge_res, &c_vertex_res));

Expand Down

0 comments on commit da02a8e

Please sign in to comment.