From radford at cs.toronto.edu  Sat Aug 13 22:56:43 2011
From: radford at cs.toronto.edu (Radford Neal)
Date: Sat, 13 Aug 2011 16:56:43 -0400
Subject: [Rd] Latent flaw in SEXPREC definition
Message-ID: <20110813205643.GA4049@cs.toronto.edu>

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;



[Rd] Latent flaw in SEXPREC definition
Radford Neal