[Rd] Possible bug in Rcons_vprintf

Jeffrey Horner jeff.horner at vanderbilt.edu
Tue Oct 3 18:09:56 CEST 2006


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




More information about the R-devel mailing list