Skip to content

Commit aa687cd

Browse files
author
ripley
committed
warn on data pointers of zero-length vectore
git-svn-id: https://svn.r-project.org/R/trunk@88219 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 8343da5 commit aa687cd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

doc/manual/R-exts.texi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14639,6 +14639,17 @@ directly would violate assumptions the memory manager depends on.
1463914639
@code{DATAPTR_RO} returns a generic read-only data pointer for any
1464014640
vector object.
1464114641

14642+
@strong{N.B.} These will return a valid data pointer only for vectors of
14643+
positive length. Zero-length vectors have no `data' and these accessors
14644+
will usually return an invalid pointer, for example to address
14645+
@code{0x000000000001}. So usages such as
14646+
@example
14647+
memcpy(REAL(newx), REAL_RO(x), LENGTH(x) * sizeof(double));
14648+
@end example
14649+
@noindent
14650+
are undefined behaviour without a prior check on the length of @code{x}.
14651+
@c Returning 0x000000000001 was inroduced in R 4.5.0.
14652+
1464214653
Formerly it was possible for packages to obtain internal versions of
1464314654
some accessors by defining @samp{USE_RINTERNALS} before including
1464414655
@file{Rinternals.h}. This is no longer the case. Defining

0 commit comments

Comments
 (0)