From p.dalgaard at biostat.ku.dk  Wed Aug  3 02:55:53 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 03 Aug 2005 02:55:53 +0200
Subject: [Rd] Follow-Up: R on FC4
In-Reply-To: <x2slxtlcpg.fsf@turmalin.kubism.ku.dk>
References: <1122915856.23831.43.camel@gsimpson.geog.ucl.ac.uk>
	<Pine.A41.4.61b.0508011013500.226770@homer10.u.washington.edu>
	<1122919754.23831.45.camel@gsimpson.geog.ucl.ac.uk>
	<x2slxtlcpg.fsf@turmalin.kubism.ku.dk>
Message-ID: <x2slxrrg86.fsf@turmalin.kubism.ku.dk>

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:
> 
>  -Wp,-D_FORTIFY_SOURCE=2 
> 
> 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



[Rd] Follow-Up: R on FC4
Peter Dalgaard