From owner-freebsd-hackers Fri Jun 8 16:44:56 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from earth.backplane.com (earth-nat-cw.backplane.com [208.161.114.67]) by hub.freebsd.org (Postfix) with ESMTP id C0DE037B405; Fri, 8 Jun 2001 16:44:53 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.11.3/8.11.2) id f58NirE99600; Fri, 8 Jun 2001 16:44:53 -0700 (PDT) (envelope-from dillon) Date: Fri, 8 Jun 2001 16:44:53 -0700 (PDT) From: Matt Dillon Message-Id: <200106082344.f58NirE99600@earth.backplane.com> To: Matt Dillon Cc: Peter Pentchev , John Baldwin , hackers@FreeBSD.ORG Subject: Re: free() and const warnings References: <20010607195634.I724@ringworld.oblivion.bg> <20010608114957.C19938@ringworld.oblivion.bg> <200106082339.f58Ndg399460@earth.backplane.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Oh my, and just posting these I found a couple of bugs! :char * :safe_replace(char **pptr, const char *s) :{ : /* : * Same data (also occurs if s == *ptr), nothing to do : */ : if (*pptr) { : if (s && strcmp(s, *pptr) == 0) : return(*pptr); : free(*pptr); : } : : /* : * free old, dup new. : */ : *pptr = (s) ? strdup(s) : NULL; : return(*pptr); :} Should call safe_strdup(), not strdup(). :char * :safe_append(char **pptr, const char *s) :{ : char *old; : char *new; : : if ((old = *pptr) != NULL) { : int newLen = strlen(old) + strlen(s) + 1; : new = malloc(newLen); : snprintf(new, newLen, "%s%s", old, s); : free(old); : } else { : new = strdup(s); : } : *pptr = new; : return(new); :} Ditto. Should call safe_strdup(), not strdup(). I probably should have cleaned the source up before posting it. I also have a fatalmem() routine which assert(0)'s, and DBASSERT(0) is simply assert(0)... really should be a fatalmem() call too. Oh well. You get the picture! -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message