Skip to content
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
5 changes: 5 additions & 0 deletions src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ SEXP growVector(SEXP x, const R_len_t newlen)
if (isNull(x)) error(_("growVector passed NULL"));
PROTECT(newx = allocVector(TYPEOF(x), newlen)); // TO DO: R_realloc(?) here?
if (newlen < len) len=newlen; // i.e. shrink
if (!len) { // cannot memcpy invalid pointer, #6819
keepattr(newx, x);
UNPROTECT(1);
return newx;
}
switch (TYPEOF(x)) {
case RAWSXP: memcpy(RAW(newx), RAW(x), len*SIZEOF(x)); break;
case LGLSXP: memcpy(LOGICAL(newx), LOGICAL(x), len*SIZEOF(x)); break;
Expand Down
11 changes: 8 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ SEXP copyAsPlain(SEXP x) {
}
const int64_t n = XLENGTH(x);
SEXP ans = PROTECT(allocVector(TYPEOF(x), n));
// aside: unlike R's duplicate we do not copy truelength here; important for dogroups.c which uses negative truelenth to mark its specials
if (ALTREP(ans))
internal_error(__func__, "copyAsPlain returning ALTREP for type '%s'", type2char(TYPEOF(x))); // # nocov
if (!n) { // cannot memcpy invalid pointer, #6819
DUPLICATE_ATTRIB(ans, x);
UNPROTECT(1);
return ans;
}
switch (TYPEOF(x)) {
case RAWSXP:
memcpy(RAW(ans), RAW(x), n*sizeof(Rbyte));
Expand Down Expand Up @@ -250,9 +258,6 @@ SEXP copyAsPlain(SEXP x) {
internal_error(__func__, "type '%s' not supported in %s", type2char(TYPEOF(x)), "copyAsPlain()"); // # nocov
}
DUPLICATE_ATTRIB(ans, x);
// aside: unlike R's duplicate we do not copy truelength here; important for dogroups.c which uses negative truelenth to mark its specials
if (ALTREP(ans))
internal_error(__func__, "copyAsPlain returning ALTREP for type '%s'", type2char(TYPEOF(x))); // # nocov
UNPROTECT(1);
return ans;
}
Expand Down
Loading