Skip to content

Segmentation fault linked to memory? (PR#929)

2 messages · Jonathan Rougier, Peter Dalgaard

#
Hi Everyone,

The following rather extreme claim on memory causes a
segmentation fault on my installation:

fred <- matrix(1:1200, 20, 60)

littleOP <- function(x, y)
{
  z <- as.vector(x) %*% t(as.vector(y))
  dim(z) <- c(dim(x), dim(y))
  z
}

littleOP(fred, fred)                 # this is OK
littleOP(littleOP(fred, fred), fred) # whoops! Segmentation fault

What's a bit strange is that if I do the outer product the
`old-fashioned' way then I get the more usual error message:
Error: cannot allocate vector of size 2555696 Kb

Cheers, Jonathan.

--please do not edit the information below--

Version:
 platform = sparc-sun-solaris2.7
 arch = sparc
 os = solaris2.7
 system = sparc, solaris2.7
 status = 
 major = 1
 minor = 2.1
 year = 2001
 month = 01
 day = 15
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
J.C.Rougier@durham.ac.uk writes:
You really ought to upgrade before reporting such bugs, but I get it
with 1.2.3 as well. Looks like we have an integer overrun issue:

At the point of the crash, we have succesfully allocated "ans" 

(gdb) p ans
$25 = (SEXPREC *) 0x1fe8038
(gdb) p Rf_length(ans)
$26 = 1728000000
(gdb) p/x Rf_length(ans)
$27 = 0x66ff3000

however, measured in *bytes*, that length won't fit in 32 bits, and

(gdb) p/x (Rf_length(ans)*8)/8
$31 = 0x6ff3000

So I suppose that the true length of ans is only

0x6ff3000

which fits fairly nicely with the segfault occurring when you try to
access cell number 82*1440000

(gdb) p/x 82*1440000
$28 = 0x709c200