Skip to content

segfault with format.POSIXct()

9 messages · Uwe Ligges, Sébastien Bihorel, Duncan Murdoch +1 more

#
Hi,

I'm getting a segmentation fault as follows:

---<--------------------cut here---------------start------------------->---
R> begt <- as.POSIXct(strptime("10/01/2009 06:00:00", format="%d/%m/%Y %H:%M:%S"),
+                    tz="GMT")
R> tser <- seq(begt, by=5, length.out=91000)
R> tser.trunc <- format(tser)
Error: segfault from C stack overflow
---<--------------------cut here---------------end--------------------->---

With the following set up:

---<--------------------cut here---------------start------------------->---
R> sessionInfo()
R version 2.11.0 RC (2010-04-19 r51778) 
x86_64-pc-linux-gnu 

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] slmisc_0.7.3   lattice_0.18-3

loaded via a namespace (and not attached):
[1] grid_2.11.0
---<--------------------cut here---------------end--------------------->---


Reducing the size of the sequence in seq.POSIXct() to 90000 doesn't
cause a segfault, so it seems to be a memory issue.  Is this a bug?

Thanks,
#
Works for me, both under Windows (32 and 64 bit) and Linux, although I 
have not package slmisc attached.

Uwe Ligges
On 23.04.2010 01:32, Sebastian P. Luque wrote:
#
On 23/04/2010 7:31 AM, Uwe Ligges wrote:
I've just found that the bug 14267 is related to a POSIXlt formatting 
bug, so this is likely to be the same thing. 

Duncan Murdoch
#
On Fri, 23 Apr 2010 07:46:10 -0400,
Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

            
I just tried with:

---<--------------------cut here---------------start------------------->---
R> sessionInfo()
R version 2.12.0 Under development (unstable) (2010-04-23 r51810) 
x86_64-unknown-linux-gnu 

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
---<--------------------cut here---------------end--------------------->---

and using a sequence of 200000 worked without problems.  It doesn't seem
as if bug 14267 has been fixed in the 2.12.0 devel version above, but
something else might have fixed the C stack overflow I'm getting.

Thanks for the pointers!
#
On Fri, 23 Apr 2010 13:31:14 +0200,
Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:

            
Is this with 2.11.0 ?  Thanks.
#
On Apr 23, 2010, at 2:50 PM, Sebastian P. Luque wrote:

            
I'm getting a bit further with bug 14267:

On OSX I am NOT seeing it with R-devel, although it is there with 2.11.0 Patched.

Running with a non-optimized compile, I can get some more information

It is happening on the i-th iteration of the loop in do_formatPOSIXlt with 

(gdb) p i
$4 = 86870

Unfortunately, it looks like a bigger exercise to get valgrind running on Snow Leopard -- too big for Friday afternoon anyway. However, the alloca() call on line 774 of src/main/datetime.c does look suspect to me. I can see that it was introduced with r51353 and has since disappeared in R-devel (r51398).

  
    
#
On 23/04/2010 10:03 AM, peter dalgaard wrote:
I've just committed a patch for this on R-2-11-branch.  The problem was 
that the alloca() was within a loop, so it kept allocating more and more 
space until the end of the function call, and blew the stack. In 
R-devel, this was changed to the C99 construct of defining a variable 
sized array within a block, and that was fine, because it was released 
at the end of the block, not at the end of the function call.

Duncan Murdoch
#
On Fri, 23 Apr 2010 16:03:15 +0200,
peter dalgaard <pdalgd at gmail.com> wrote:

            
So it does seems as if this is all related to that bug, which somehow
got fixed in R-devel.

Thanks everyone,
#
On Apr 23, 2010, at 4:17 PM, Duncan Murdoch wrote:

            
Yes, that's what I suspected. Thanks for the fix!

-p