Skip to content

Commit 5dbfca1

Browse files
committed
Explicitly protect temporary vector in no_init()
1 parent 522e66d commit 5dbfca1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

inst/include/Rcpp/vector/no_init.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ class no_init_vector {
3535
return size;
3636
}
3737

38-
template <int RTYPE, template <class> class StoragePolicy >
39-
operator Vector<RTYPE, StoragePolicy>() const {
40-
return Rf_allocVector(RTYPE, size) ;
38+
template <int RTYPE>
39+
operator Vector<RTYPE, PreserveStorage>() const {
40+
SEXP x = PROTECT(Rf_allocVector(RTYPE, size));
41+
Vector<RTYPE, PreserveStorage> ret(x);
42+
UNPROTECT(1);
43+
return ret;
4144
}
4245

4346
private:

0 commit comments

Comments
 (0)