Skip to content

Commit 94fcf92

Browse files
Update src/dogroups.c
Co-authored-by: Michael Chirico <[email protected]>
1 parent 52924e9 commit 94fcf92

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/dogroups.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,12 @@ SEXP growVector(SEXP x, const R_len_t newlen)
535535
if (isNull(x)) error(_("growVector passed NULL"));
536536
PROTECT(newx = allocVector(TYPEOF(x), newlen)); // TO DO: R_realloc(?) here?
537537
if (newlen < len) len=newlen; // i.e. shrink
538-
if (len) switch (TYPEOF(x)) {
538+
if (!len) { // cannot memcpy invalid pointer, #6819
539+
keepattr(newx, x)
540+
UNPROTECT(1);
541+
return newx;
542+
}
543+
switch (TYPEOF(x)) {
539544
case RAWSXP: memcpy(RAW(newx), RAW(x), len*SIZEOF(x)); break;
540545
case LGLSXP: memcpy(LOGICAL(newx), LOGICAL(x), len*SIZEOF(x)); break;
541546
case INTSXP: memcpy(INTEGER(newx), INTEGER(x), len*SIZEOF(x)); break;

0 commit comments

Comments
 (0)