Skip to content

Commit f5dc296

Browse files
authored
fix: Fix protection errors reported by rchk (#1592)
1 parent e735c3f commit f5dc296

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@
5656
^man/dot-extract_constructor_and_modifiers\.Rd$
5757
^man/dot-apply_modifiers\.Rd$
5858
^man/handle_vertex_type_arg\.Rd$
59+
^build$
60+
^libs$

src/rinterface_extra.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ SEXP R_igraph_get_attr_mode(SEXP graph, SEXP pwhich) {
253253

254254
igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *comb) {
255255
igraph_integer_t n = Rf_xlength(input);
256-
SEXP names = PROTECT(GET_NAMES(input));
257256

258257
IGRAPH_CHECK(igraph_attribute_combination_init(comb));
259258
IGRAPH_FINALLY(igraph_attribute_combination_destroy, comb);
@@ -264,10 +263,10 @@ igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *c
264263
igraph_function_pointer_t func;
265264

266265
/* Name */
267-
if (!Rf_isNull(names)) {
268-
name = CHAR(STRING_ELT(names, i));
266+
if (!Rf_isNull(GET_NAMES(input))) {
267+
name = CHAR(STRING_ELT(GET_NAMES(input), i));
269268
}
270-
if (Rf_isNull(names) || strlen(name) == 0) {
269+
if (name && strlen(name) == 0) {
271270
name = NULL;
272271
}
273272

@@ -283,13 +282,12 @@ igraph_error_t R_SEXP_to_attr_comb(SEXP input, igraph_attribute_combination_t *c
283282
}
284283

285284
IGRAPH_FINALLY_CLEAN(1);
286-
UNPROTECT(1);
287285
return IGRAPH_SUCCESS;
288286
}
289287

290288
static SEXP R_igraph_attribute_preserve_list;
291289

292-
void R_igraph_attribute_add_to_preserve_list(SEXP attr) {
290+
SEXP R_igraph_attribute_add_to_preserve_list(SEXP attr) {
293291
if (!R_igraph_attribute_preserve_list) {
294292
// We don't care about freeing this, typically this is just a single node
295293
R_igraph_attribute_preserve_list = Rf_cons(R_NilValue, R_NilValue);
@@ -299,6 +297,7 @@ void R_igraph_attribute_add_to_preserve_list(SEXP attr) {
299297
// Create a new node, add it to the head of the list.
300298
SEXP node = Rf_cons(attr, CDR(R_igraph_attribute_preserve_list));
301299
SETCDR(R_igraph_attribute_preserve_list, node);
300+
return attr;
302301
}
303302

304303
void R_igraph_attribute_clean_preserve_list(void) {
@@ -320,9 +319,10 @@ igraph_error_t R_igraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *att
320319
int px = 0;
321320

322321
result=PROTECT(NEW_LIST(4));
323-
// The "preserve list" Will be cleared with the next invocation of IGRAPH_R_CHECK().
322+
// The "preserve list" will be cleared with the next invocation of an igraph function.
324323
// Adding to that list ensures that the attributes aren't GC-ed prematurely.
325-
R_igraph_attribute_add_to_preserve_list(result);
324+
result = R_igraph_attribute_add_to_preserve_list(result);
325+
UNPROTECT(1);
326326

327327
/* Add dummy vector for compatibility with CRAN versions */
328328
SEXP dummy = NEW_NUMERIC(3);
@@ -338,7 +338,6 @@ igraph_error_t R_igraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *att
338338
SET_VECTOR_ELT(result, i, attr); /* gal, val, eal */
339339
UNPROTECT(1);
340340
}
341-
UNPROTECT(1);
342341
graph->attr=result;
343342

344343
/* Add graph attributes */

0 commit comments

Comments
 (0)