Skip to content

bus error /segmentation fault from 'approx' (PR#7177)

2 messages · Joerg van den Hoff, Peter Dalgaard

#
Full_Name: joerg  van den hoff
Version: 1.9.1
OS: MacOS  and SunOS 
Submission from: (NULL) (149.220.4.88)


follow up to ID 7166. something like

approx(c(1,2),c(NA,NA),1.5,rule=2)

crashes 1.9.1 on both systems (MacOS 10.3.5.: bus error,  SunOS 5.9:
segmentation fault) even if xout is within given x range (as in example above)
where rule=2 seems not be relevant anyway.
#
j.van_den_hoff@fz-rossendorf.de writes:
Yes, this is a silly bug in the R driver routine:


    if (nx < 2 && method == "linear")
        stop("approx requires at least two values to interpolate")
    if (any(na <- is.na(x) | is.na(y))) {
        ok <- !na
        x <- x[ok]
        y <- y[ok]
        nx <- length(x)
    }

You want to do the check after removing NAs! 

Also, we should probably have a check for (nx == 0 && method != "linear")