[R] segmentation fault with sprintf(), sometimes

About this list Date view Thread view Subject view Author view Attachment view

From: Don MacQueen (macq@llnl.gov)
Date: Fri 07 May 2004 - 01:56:51 EST


Message-id: <p06002007bcc010a4138d@[128.115.153.6]>

By mistake I supplied sprintf() with a bad format specification. I
got a segmentation fault. But not every time.

> version
           _
platform sparc-sun-solaris2.8
arch sparc
os solaris2.8
system sparc, solaris2.8
status Patched
major 1
minor 9.0
year 2004
month 04
day 30
language R

> sprintf('%.-0.999f',3)
Segmentation fault

The format string makes no sense, of course, so one should expect
something bad to happen. But preferably not that bad!

Also, the behavior is to some degree indeterminate. Sometimes I get this:

> sprintf('%.-0.999f',3)
[1]
"0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000!
  0
000000000000"

I haven't identified anything that might determine which the above
responses occurs.

On another platform, note that the formatted string begins with "3",
not "0" as above.

> version
           _
platform powerpc-apple-darwin6.8.5
arch powerpc
os darwin6.8.5
system powerpc, darwin6.8.5
status Patched
major 1
minor 9.0
year 2004
month 04
day 30
language R
> sprintf('%.-0.999f',3)
[1]
"3.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000!
  0
000000000000"
>

The behavior is no doubt dependent on the operating system's sprintf,
for I find in R's sprintf.c:

/* Simple wrapper for C sprintf function: now (1.6.0) checks the
     types and handles the R specials.
*/

-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:08 EST