[Rd] Follow-Up: R on FC4

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Aug 3 02:55:53 CEST 2005

Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:

> Gavin Simpson <gavin.simpson at ucl.ac.uk> writes:
> > So far so good with FC4, gcc4, gfortran and R!
> The problem affecting the Fedora Extras RPM is still there with the
> new compilers though:
> combined with -O or -O2 causes a strange printing bug:
> > matrix(list(pi))
>      [,1]
> [1,]
> (You don't have to use that option of course, but it suggests that not
> all is well with the optimizer. And the Fedora maintainer seem set on
> using it, which is a bit of a problem.)

I'm fairly sure by now that this is actually a bug in R, not gcc. We
have the same internal buffer structure used in EncodeReal and in
Rsprintf, and the return value of the former is buffer->data
which is reallocated by the latter.

That means that constructions of the form

pbuf = Rsprintf("%s", EncodeReal(REAL(tmp)[0], w, d, e, OutDec));

are playing with fire. There are quite a few other similar
constructions involving Encode*.

I suspect is is necessary to copy the result of
EncodeReal(REAL(tmp)[0], w, d, e, OutDec) to temp storage, or -
probably easier - use a separate buffer for Rsprintf.

   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

More information about the R-devel mailing list