Skip to content

Commit 6cab64d

Browse files
committed
Return null start for empty vectors
1 parent b2f6ad8 commit 6cab64d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2026-03-26 Iñaki Ucar <iucar@fedoraproject.org>
2+
3+
* inst/include/Rcpp/internal/r_vector.h: Return null start for empty vectors
4+
instead of an invalid pointer, which causes UB in e.g. std::copy
5+
16
2026-03-06 Dirk Eddelbuettel <edd@debian.org>
27

38
* DESCRIPTION (Version, Date): Roll micro version and date (twice)

inst/include/Rcpp/internal/r_vector.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//
44
// r_vector.h: Rcpp R/C++ interface class library -- information about R vectors
55
//
6-
// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
6+
// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain François
7+
// Copyright (C) 2026 Dirk Eddelbuettel, Romain François and Iñaki Ucar
78
//
89
// This file is part of Rcpp.
910
//
@@ -36,6 +37,8 @@ typename Rcpp::traits::storage_type<RTYPE>::type* r_vector_start(SEXP x) {
3637
#define RCPP_VECTOR_START_IMPL(__RTYPE__, __ACCESSOR__) \
3738
template <> \
3839
inline typename Rcpp::traits::storage_type<__RTYPE__>::type* r_vector_start<__RTYPE__>(SEXP x) { \
40+
if (Rf_xlength(x) == 0) \
41+
return NULL; \
3942
return __ACCESSOR__(x); \
4043
}
4144

0 commit comments

Comments
 (0)