Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -11272,7 +11272,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
18 changes: 18 additions & 0 deletions src/rinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *c
else if (__c != IGRAPH_SUCCESS) { R_igraph_error(); } \
} while (0)

// 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((func##_pv), (ptr)); \
} while (0)

// These functions are never meant to be called directly, only through IGRAPH_FINALLY_PV.
void igraph_destroy_pv(void *pv_ptr);
void igraph_matrix_destroy_pv(void *pv_ptr);
void igraph_vector_destroy_pv(void *pv_ptr);
void igraph_vector_int_destroy_pv(void *pv_ptr);
void igraph_vector_bool_destroy_pv(void *pv_ptr);
void igraph_vector_int_list_destroy_pv(void *pv_ptr);

#define IGRAPH_R_CHECK_INT(v) R_check_int_scalar(v)
#define IGRAPH_R_CHECK_REAL(v) R_check_real_scalar(v)
#define IGRAPH_R_CHECK_BOOL(v) R_check_bool_scalar(v)
Expand Down
Loading