Skip to content

Attempt to fix rchk issue related to names #409

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

Merged
merged 1 commit into from
Dec 3, 2024
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: 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).

* `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).
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
Loading