Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use _pv destroy functions to satisfy ASAN checks #1630

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 17 additions & 0 deletions src/rinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ 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)

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
Loading