Skip to content
Prev 30529 / 63421 Next

(PR#13283) R crashes on sprintf with bad format specification

As R's sprintf is a wrapper for the OS's sprintf, misuse does run the risk 
of crashing from OS, and when it does the error will come from the 
implementation of sprintf (which for R for Windows is the Trio library).
One could argue that the OS service should not segfault on incorrect 
input, but this one often does.

The place to add checks is in the R wrapper code (presumably in the C 
component).  We do have checks there, but it is hard to imagine just what 
errors users will make, and this one has slipped through the checks.

Here the issue is the use of %S, an unknown format for numbers, followed 
by 'X'.  There is a check for a suitable format, but it is not strict 
enough.  And it is non-trivial to write a printf format parser just to 
check for user error (and potentially it will slow down correct uses: 
speed in sprintf is important in some applications).

So I am not sure this is something that should be R's responsibility to 
fix: maybe just add a warning to the help page?
On Thu, 13 Nov 2008, Duncan Murdoch wrote:

            
R is not C, and the empty command at the end of that line (after the 
semicolon) is not relevant.