[Rd] Latent flaw in SEXPREC definition

Radford Neal radford at cs.toronto.edu
Sat Aug 13 22:56:43 CEST 2011


There seems to be a latent flaw in the definition of struct SEXPREC
in Rinternals.h, which likely doesn't cause problems now, but could
if the relative sizes of data types changes.

The SEXPREC structure contains a union that includes a primsxp,
symsxp, etc, but not a vecsxp.  However, in allocVector in memory.c,
zero-length vectors are allocated using allocSExpNonCons, which
appears to allocates a SEXPREC structure.  This won't work if a vecsxp
is larger than the other types that are in the union in the SEXPREC
structure.

Simply adding a vecsxp to the union would seem to fix this, as in
the following patch:

Index: src/include/Rinternals.h
===================================================================
--- src/include/Rinternals.h    (revision 56640)
+++ src/include/Rinternals.h    (working copy)
@@ -219,6 +219,7 @@
 typedef struct SEXPREC {
     SEXPREC_HEADER;
     union {
+       struct vecsxp_struct vecsxp;
        struct primsxp_struct primsxp;
        struct symsxp_struct symsxp;
        struct listsxp_struct listsxp;



More information about the R-devel mailing list