ntakebay@bio.indiana.edu
1999-Oct-30 23:29 UTC
read.table problem on Linux/Alpha (seg faults caused by isspace(R_EOF)) (PR#303)
Full_Name: Naoki Takebayashi Version: 0.65.1 OS: Linux/Alpha Submission from: (NULL) (129.79.224.171) When I was reading a file with read.table("junk.data"), it seg-faulted. I found out that it seg-faulted when the last line of data file didn't have the newline char. For example, file like this: 23 3 31 2 24 1<EOF> Here is a fix. --- R-0.65.1/src/main/scan.c.orig Wed Sep 29 11:11:45 1999 +++ R-0.65.1/src/main/scan.c Fri Oct 29 17:34:22 1999 @@ -124,7 +124,7 @@ if (bufp >= &buffer[MAXELTSIZE - 2]) continue; *bufp++ = c; - } while (!isspace(c = scanchar()) && c != R_EOF); + } while ((c = scanchar()) != R_EOF && !isspace(c)); while (c==' ' || c=='\t') c=scanchar(); if (c=='\n' || c=='\r' || c==R_EOF) @@ -647,7 +647,7 @@ } } else { - while (!isspace(c=scanchar()) && c != R_EOF) + while ( (c=scanchar()) != R_EOF && !isspace(c)) ; if (c==R_EOF) c='\n'; unscanchar(c); When the scanchar() returns R_EOF (=65535 #defined in src/include/Defn.h), isspace(R_EOF) seq-faults. By switching the order of two conditions, I could get around with it. I just made a test to see the behavior of isspace() by giving isspace(65535). It seg-faults in both Linux/alpha and i386 (is it supposed to??). However, R on i386 doesn't seg-faults when the last line does not have newline. Naoki -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
1999-Oct-31 12:30 UTC
read.table problem on Linux/Alpha (seg faults caused by isspace(R_EOF)) (PR#303)
ntakebay@bio.indiana.edu writes:> Here is a fix. > > --- R-0.65.1/src/main/scan.c.orig Wed Sep 29 11:11:45 1999 > +++ R-0.65.1/src/main/scan.c Fri Oct 29 17:34:22 1999 > @@ -124,7 +124,7 @@ > if (bufp >= &buffer[MAXELTSIZE - 2]) > continue; > *bufp++ = c; > - } while (!isspace(c = scanchar()) && c != R_EOF); > + } while ((c = scanchar()) != R_EOF && !isspace(c));....> When the scanchar() returns R_EOF (=65535 #defined in src/include/Defn.h), > isspace(R_EOF) seq-faults. By switching the order of two conditions, I could > get around with it. I just made a test to see the behavior of isspace() by > giving > isspace(65535). It seg-faults in both Linux/alpha and i386 (is it supposed > to??). > However, R on i386 doesn't seg-faults when the last line does not have newline.Thanks. However, perhaps a better fix would be to change R_EOF? All the isxxx macros/functions work by indexing an array designed to take values between -128 and +255, so passing 65535 is playing with fire, and we have many more instances littered all over the code, where I don't feel absolutely sure that R_EOF couldn't sneak in. Any one remember why R_EOF is different from the customary EOF of -1?? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._