From jeff.horner at vanderbilt.edu  Tue Oct  3 18:09:56 2006
From: jeff.horner at vanderbilt.edu (Jeffrey Horner)
Date: Tue, 03 Oct 2006 11:09:56 -0500
Subject: [Rd] Possible bug in Rcons_vprintf
In-Reply-To: <17694.33006.587070.870361@stat.math.ethz.ch>
References: <451D809B.3060906@vanderbilt.edu>
	<17694.33006.587070.870361@stat.math.ethz.ch>
Message-ID: <45228B54.2010604@vanderbilt.edu>

Martin Maechler wrote:
> Thanks, Jeffrey,
> 
> that (change) looks very logical, reasonable, ...
> and I'll commit a patch to R-devel ASAP.
> 
> On the other hand, I'm currently not intending to port the fix
> to the currently "deep frozen" R-2.4-branch [because "you never know ..."]
> unless you can argue a bit more why the change seems important 
> (or at least can demonstrate bogous behavior that is fixed by it).

Not a big deal at the moment... although I would have argued for its 
inclusion into R 2.4 if rJava, a well established package used by JGR, 
demonstrated bogus behavior... because it does depend on R_WriteConsole, 
but it turns out that rjava ignores the second argument defining the 
length of the buffer to be printed. Is this appropriate?

rJava is making an assumption that in a call to R_WriteConsole, the 
buffer is always null terminated, and this seems supported by the R 
source. The following grep output on R-2-4-branch (but probably in 
R-trunk, too) shows that each call to R_WriteConsole *does* pass 
null-terminated strings:

# some of the output has been edited
$ find . -follow -name '*.[ch]' | xargs grep -B 1 R_WriteConsole
./src/library/grDevices/src/devWindows.c-    setstatus(msg);
./src/library/grDevices/src/devWindows.c:    R_WriteConsole(msg, 
strlen(msg));
./src/library/grDevices/src/devWindows.c:    R_WriteConsole("\n", 1);
--
./src/main/printutils.c-#endif /* HAVE_VA_COPY */
./src/main/printutils.c:    R_WriteConsole(p, strlen(buf));
--
./src/main/printutils.c-        slen = strlen(buf);
./src/main/printutils.c:        R_WriteConsole(buf, slen);
--
./src/gnuwin32/sys-win32.c-             } else
./src/gnuwin32/sys-win32.c:                 R_WriteConsole(buf, 
strlen(buf));
--
./src/gnuwin32/system.c-                            buf[len] = '\0';
./src/gnuwin32/system.c:                            R_WriteConsole(buf, 
strlen(buf));
--
./src/gnuwin32/system.c-        fflush(R_Consolefile);
./src/gnuwin32/system.c:    } else R_WriteConsole(s, strlen(s));


Jeff

> 
> Martin
> 
>>>>>> "Jeffrey" == Jeffrey Horner <jeff.horner at vanderbilt.edu>
>>>>>>     on Fri, 29 Sep 2006 15:22:51 -0500 writes:
> 
>     Jeffrey> In R-2-4-branch r39548, Rcons_vprintf is called from stdout_vfprintf 
>     Jeffrey> when R_Outputfile is NULL. When called and output is greater than 
>     Jeffrey> R_BUFSIZE, output is truncated to R_BUFSIZE. Here's a one-line fix:
> 
>     Jeffrey> Index: src/main/printutils.c
>     Jeffrey> ===================================================================
>     Jeffrey> --- src/main/printutils.c       (revision 39548)
>     Jeffrey> +++ src/main/printutils.c       (working copy)
>     Jeffrey> @@ -638,7 +638,7 @@
>     Jeffrey> res = R_BUFSIZE;
>     Jeffrey> }
>     Jeffrey> #endif /* HAVE_VA_COPY */
>     Jeffrey> -    R_WriteConsole(p, strlen(buf));
>     Jeffrey> +    R_WriteConsole(p, strlen(p));
>     Jeffrey> #ifdef HAVE_VA_COPY
>     Jeffrey> if(usedRalloc) vmaxset(vmax);
>     Jeffrey> if(usedVasprintf) free(p);
> 
> 
>     Jeffrey> Jeff
>     Jeffrey> -- 
>     Jeffrey> http://biostat.mc.vanderbilt.edu/JeffreyHorner
> 


-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner




[Rd] Possible bug in Rcons_vprintf
Jeffrey Horner