Platform-specific: simple assignments in Rprofile cause core dump (PR#1604)

NEFTH@pacbell.net NEFTH@pacbell.net
Tue, 28 May 2002 08:42:00 +0200 (MET DST)


This is a multi-part message in MIME format.

--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT


This only happens on platforms with a faulty implementation
of realloc(). Some C libraries do not allow realloc() to be
called with a NULL pointer to resize. The assignment

ISOLatin1 <- 0:255

in Rprofile then causes a core dump. The attached set
of 4 patches should be very safe to use and fix the problem.

--please do not edit the information below--

Version:
 platform = i386-pc-sco3.2v4.2
 arch = i386
 os = sco3.2v4.2
 system = i386, sco3.2v4.2
 status = 
 major = 1
 minor = 4.1
 year = 2002
 month = 01
 day = 30
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base


--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)
Content-type: text/plain; name=SCOPATCH_character.c.txt
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=SCOPATCH_character.c.txt

*** character.c.orig	Wed Sep 19 09:04:16 2001
--- character.c	Sun May 12 00:54:18 2002
***************
*** 75,81 ****
  	if(len*sizeof(char) < bufsize) return;
  	len = (len+1)*sizeof(char);
  	if(len < MAXELTSIZE) len = MAXELTSIZE;
! 	buff = (char *) realloc(buff, len);
  	bufsize = len;
  	if(!buff) {
  	    bufsize = 0;
--- 75,85 ----
  	if(len*sizeof(char) < bufsize) return;
  	len = (len+1)*sizeof(char);
  	if(len < MAXELTSIZE) len = MAXELTSIZE;
! 	if(buff==NULL){
! 	    buff = (char *) malloc(len);
! 	} else {
! 	    buff = (char *) realloc(buff, len);
! 	}
  	bufsize = len;
  	if(!buff) {
  	    bufsize = 0;
***************
*** 267,273 ****
  		PROTECT(t = allocVector(STRSXP, ntok + 1));
  	    /* and fill with the splits */
  	    bufp = buff;
! 	    pt = (char *) realloc(pt, (strlen(buff)+1) * sizeof(char));
  	    for(j = 0; j < ntok; j++) {
  		regexec(&reg, bufp, 1, regmatch, eflags);
  		if(regmatch[0].rm_eo > 0) {
--- 271,281 ----
  		PROTECT(t = allocVector(STRSXP, ntok + 1));
  	    /* and fill with the splits */
  	    bufp = buff;
! 	    if(pt==NULL){
! 	        pt = (char *) malloc((strlen(buff)+1) * sizeof(char));
! 	    } else {
! 	        pt = (char *) realloc(pt, (strlen(buff)+1) * sizeof(char));
! 	    }
  	    for(j = 0; j < ntok; j++) {
  		regexec(&reg, bufp, 1, regmatch, eflags);
  		if(regmatch[0].rm_eo > 0) {

--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)
Content-type: text/plain; name=SCOPATCH_memory.c.txt
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=SCOPATCH_memory.c.txt

*** memory.c.orig	Tue Nov 27 02:41:16 2001
--- memory.c	Sun May 12 00:41:44 2002
***************
*** 2030,2036 ****
  void *R_chk_realloc(void *ptr, size_t size)
  {
      void *p;
!     p = realloc(ptr, size);
      if(!p) error("Realloc could not re-allocate (size %d) memory", size);
      return(p);
  }
--- 2030,2040 ----
  void *R_chk_realloc(void *ptr, size_t size)
  {
      void *p;
!     if(ptr==NULL){
! 	p = malloc(size);
!     } else {
! 	p = realloc(ptr, size);
!     }
      if(!p) error("Realloc could not re-allocate (size %d) memory", size);
      return(p);
  }

--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)
Content-type: text/plain; name=SCOPATCH_printutils.c.txt
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=SCOPATCH_printutils.c.txt

*** printutils.c.orig	Tue Oct 30 06:18:10 2001
--- printutils.c	Sun May 12 01:08:14 2002
***************
*** 73,79 ****
      if(len*sizeof(char) < bufsize) return;
      len = (len+1)*sizeof(char);
      if(len < BUFSIZE) len = BUFSIZE;
!     Encodebuf = (char *) realloc(Encodebuf, len);
      bufsize = len;
      if(!Encodebuf) {
  	bufsize = 0;
--- 73,83 ----
      if(len*sizeof(char) < bufsize) return;
      len = (len+1)*sizeof(char);
      if(len < BUFSIZE) len = BUFSIZE;
!     if(Encodebuf==NULL) {
!         Encodebuf = (char *) malloc(len);
!     } else {
!         Encodebuf = (char *) realloc(Encodebuf, len);
!     }
      bufsize = len;
      if(!Encodebuf) {
  	bufsize = 0;

--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)
Content-type: text/plain; name=SCOPATCH_saveload.c.txt
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=SCOPATCH_saveload.c.txt

*** saveload.c.orig	Tue Dec  4 08:52:41 2001
--- saveload.c	Sun May 12 01:16:44 2002
***************
*** 87,93 ****
  	if(len*sizeof(char) < bufsize) return;
  	len = (len+1)*sizeof(char);
  	if(len < MAXELTSIZE) len = MAXELTSIZE;
! 	buf = (char *) realloc(buf, len);
  	bufsize = len;
  	if(!buf) {
  	    bufsize = 0;
--- 87,97 ----
  	if(len*sizeof(char) < bufsize) return;
  	len = (len+1)*sizeof(char);
  	if(len < MAXELTSIZE) len = MAXELTSIZE;
! 	if(buf==NULL){
! 	    buf = (char *) malloc(len);
! 	} else {
! 	    buf = (char *) realloc(buf, len);
! 	}
  	bufsize = len;
  	if(!buf) {
  	    bufsize = 0;

--Boundary_(ID_S+/3Ro4Z3k6S6Z4btch70w)--

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