[Rd] names(unlist(...)) may construct corrupt strings (PR#1524)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Tue, 7 May 2002 18:26:09 +0200 (MET DST)


On Tue, 7 May 2002, Thomas Lumley wrote:

> On Tue, 7 May 2002 oehl_list@gmx.de wrote:
>
> > names(unlist(...)) seems to be able to construct corrupt strings
> > detected via: two identical strings behave different in paste
> > observed in RW1.4.1 and RW1.5.0
> > pure replication code after output
> >
> > Best
> >
> >
> > Jens Oehlschlägel
> >
> >
> > > l <- names(unlist(list(aa = list(bb = 1))))
> > > l
> > [1] "aa.bb"
>
> This is the same problem with do_paste that showed up with read.dta. If
> you look at the C level, LENGTH() is 6 for l and 5 for "aa.bb".
>
> In general we have the problem that a string has two ways of defining its
> length:  LENGTH() and strlen()
>
> Most functions use just one of these, but paste() uses LENGTH() to set up
> the buffer and then strcpy() to copy into it. The string l has LENGTH 6,
> but strlen 5, and the result from paste() is a string with a null as its
> sixth character, which thus appears to be a five-character string.
>
> Given that this is the second appearance of the problem perhaps do_paste()
> should be changed instead of (as well as?) unlist().

I'm fixing both.  The root bug is on line 334 of bind.c.

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._