Skip to content

Commit

Permalink
Attempt to fix rchk issue related to names
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Dec 3, 2024
1 parent dc93fb8 commit f1325f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cpp11 (development version)

* Fixed a small protection issue flagged by rchk (#408).

# cpp11 0.5.0

## R non-API related changes
Expand Down
5 changes: 3 additions & 2 deletions inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,8 @@ inline SEXP r_vector<T>::reserve_data(SEXP x, bool is_altrep, R_xlen_t size) {
SEXP out = PROTECT(resize_data(x, is_altrep, size));

// Resize names, if required
SEXP names = Rf_getAttrib(x, R_NamesSymbol);
// Protection seems needed to make rchk happy
SEXP names = PROTECT(Rf_getAttrib(x, R_NamesSymbol));
if (names != R_NilValue) {
if (Rf_xlength(names) != size) {
names = resize_names(names, size);
Expand All @@ -1338,7 +1339,7 @@ inline SEXP r_vector<T>::reserve_data(SEXP x, bool is_altrep, R_xlen_t size) {
// Does not look like it would ever error in our use cases, so no `safe[]`.
Rf_copyMostAttrib(x, out);

UNPROTECT(1);
UNPROTECT(2);
return out;
}

Expand Down

0 comments on commit f1325f9

Please sign in to comment.