[Rd] Segmentation fault, devPS.c, 0.99.0 (PR#413)

p.dalgaard@biostat.ku.dk
2000-02-08T19:47:29Z

Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

> I wouldn't think so! 0x20203665 looks suspiciously like a bit of a text
> string. "e6  " to be precise (give or take byte ordering issues).
And
> the pointer is not pointing anywhere useful. I think something is
> walking over  pd->psfp
>
> Next step would be to find out where that happens. If you set a

OK, it's dead and strsplit() was to blame. Here's the patch

Index: src/main/character.c
==================================================================RCS file:
/home/rdevel/CVS-ARCHIVE/R/src/main/character.c,v
retrieving revision 1.34
diff -u -r1.34 character.c
--- src/main/character.c	2000/01/21 16:49:19	1.34
+++ src/main/character.c	2000/02/08 19:38:16
@@ -150,7 +150,7 @@
 {
     SEXP s, t, tok, x;
     int i, j, len, tlen, ntok;
-    char *pt = NULL, *split = "";
+    char *pt = NULL, *split = "", *bufp;
     regex_t reg;
     regmatch_t regmatch[1];

@@ -177,39 +177,40 @@
 	       */
 	    if(regcomp(&reg, split, 0))
 		errorcall(call, "invalid split pattern");
-	    while(regexec(&reg, buff, 1, regmatch, 0) == 0) {
+	    bufp = buff;
+	    while(regexec(&reg, bufp, 1, regmatch, 0) == 0) {
 		/* Empty matches get the next char, so move by one. */
-		buff += MAX(regmatch[0].rm_eo, 1);
+		bufp += MAX(regmatch[0].rm_eo, 1);
 		ntok++;
-		if (*buff == '\0')
+		if (*bufp == '\0')
 		    break;
 	    }
-	    if(*buff == '\0')
+	    if(*bufp == '\0')
 		PROTECT(t = allocVector(STRSXP, ntok));
 	    else
 		PROTECT(t = allocVector(STRSXP, ntok + 1));
 	    /* and fill with the splits */
-	    strcpy(buff, CHAR(STRING(x)[i]));
+	    bufp = buff;
 	    pt = (char *) realloc(pt, (strlen(buff)+1)*sizeof(char));
 	    for(j = 0; j < ntok; j++) {
-		regexec(&reg, buff, 1, regmatch, 0);
+		regexec(&reg, bufp, 1, regmatch, 0);
 		if(regmatch[0].rm_eo > 0) {
 		    /* Match was non-empty. */
 		    if(regmatch[0].rm_so > 0)
-			strncpy(pt, buff, regmatch[0].rm_so);
+			strncpy(pt, bufp, regmatch[0].rm_so);
 		    pt[regmatch[0].rm_so] = '\0';
-		    buff += regmatch[0].rm_eo;
+		    bufp += regmatch[0].rm_eo;
 		}
 		else {
 		    /* Match was empty. */
-		    pt[0] = *buff;
+		    pt[0] = *bufp;
 		    pt[1] = '\0';
 		    buff++;
 		}
 		STRING(t)[j] = mkChar(pt);
 	    }
-	    if(*buff != '\0')
-		STRING(t)[ntok] = mkChar(buff);
+	    if(*bufp != '\0')
+		STRING(t)[ntok] = mkChar(bufp);
 	}
 	else {
 	    char bf[2];


--
   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