Subject: read.table problem on Linux/Alpha (seg faults caused by isspace(R_EOF)) (PR#303)
Date: Sun 31 Oct 1999 - 09:29:06 EST
Full_Name: Naoki Takebayashi
Submission from: (NULL) (220.127.116.11)
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:
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])
*bufp++ = c;
- } while (!isspace(c = scanchar()) && c != R_EOF);
+ } while ((c = scanchar()) != R_EOF && !isspace(c));
while (c==' ' || c=='\t')
if (c=='\n' || c=='\r' || c==R_EOF)
@@ -647,7 +647,7 @@
- while (!isspace(c=scanchar()) && c != R_EOF)
+ while ( (c=scanchar()) != R_EOF && !isspace(c))
if (c==R_EOF) c='\n';
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
isspace(65535). It seg-faults in both Linux/alpha and i386 (is it supposed
However, R on i386 doesn't seg-faults when the last line does not have newline.
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: firstname.lastname@example.org
This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:09 EST