[Rd] (PR#7326)(inappropriate) manipulation of expression objects causes segfault (PR#7326)

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Nov 1 19:50:11 CET 2004


On 29 Oct 2004, Peter Dalgaard wrote:

> deepayan at stat.wisc.edu writes:
> 
> > > foo <- expression(alpha, beta, gamma)
> > > foo[2]
> > expression(beta)
> > > foo[2] <- NA
> > > foo ## or str(foo)
> > Segmentation fault
> > 
> > (Same behaviour in R 1.9.1)
> > 
> > 'foo[[2]] <- NA' works fine, though.
> 
> Right. The NA is not important; foo[2] <- 1 crashes R just as
> effectively. We should likely either give an error or demote [ to [[.
> The latter is what happens with lists, and expressions are basically
> just list of call objects (or names or constants). To wit:
> 
> > x <- list(1,2,3)
> > x[2] <- 1
> > x
> [[1]]
> [1] 1
> 
> [[2]]
> [1] 1
> 
> [[3]]
> [1] 3

That's not the issue: VectorAssign has identical code for the vector list 
and expression cases.  The issue is in SubassignTypeFix which says

    case 2010:	/* expression <- logical    */
	/* Note : No coercion is needed here. */
	/* We just insert the RHS into the LHS. */
	/* FIXME: is this true or should it be just like the "vector" case? */

and at level=1 the FIXME is correct.

Brian

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list