diff --git a/NEWS.md b/NEWS.md index 39f3d4c1..d692aa0d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # cpp11 (development version) +* Fixed a small protection issue flagged by rchk (#408). + * `R_NO_REMAP` and `STRICT_R_HEADERS` are now conditionally defined only if they have not already been defined elsewhere. This is motivated by the fact that `R_NO_REMAP` is becoming the default for C++ code in R 4.5.0 (#410). diff --git a/inst/include/cpp11/r_vector.hpp b/inst/include/cpp11/r_vector.hpp index 9ad0b6fd..576f4fe6 100644 --- a/inst/include/cpp11/r_vector.hpp +++ b/inst/include/cpp11/r_vector.hpp @@ -1323,7 +1323,8 @@ inline SEXP r_vector::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); @@ -1338,7 +1339,7 @@ inline SEXP r_vector::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; }