On Thursday 16 October 2003 06:36 am, Jun-ichiro itojun Hagino wrote:
Module Name: src
Committed By: itojun
Date: Thu Oct 16 06:36:51 UTC 2003
Modified Files:
src/usr.bin/whois: whois.c
Log Message:
safer use of realloc
This is not in *any* way "safer." In practice it does nothing different at
all. It is code churning for the sake of code churning. This kind of utter
nonsense has introduced new bugs almost every time, and is *clearly* not
worthwhile.
------------------------------------------------------------------------
Index: src/usr.bin/whois/whois.c
diff -c src/usr.bin/whois/whois.c:1.24 src/usr.bin/whois/whois.c:1.25
*** src/usr.bin/whois/whois.c:1.24 Sat Oct 11 09:06:03 2003
--- src/usr.bin/whois/whois.c Thu Oct 16 06:36:51 2003
***************
*** 1,4 ****
! /* $NetBSD: whois.c,v 1.24 2003/10/11 09:06:03 wiz Exp $ */
/* $OpenBSD: whois.c,v 1.28 2003/09/18 22:16:15 fgsch Exp $ */
/*
--- 1,4 ----
! /* $NetBSD: whois.c,v 1.25 2003/10/16 06:36:51 itojun Exp $ */
/* $OpenBSD: whois.c,v 1.28 2003/09/18 22:16:15 fgsch Exp $ */
/*
***************
*** 41,47 ****
#if 0
static const char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
#else
! __RCSID("$NetBSD: whois.c,v 1.24 2003/10/11 09:06:03 wiz Exp $");
#endif
#endif /* not lint */
--- 41,47 ----
#if 0
static const char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
#else
! __RCSID("$NetBSD: whois.c,v 1.25 2003/10/16 06:36:51 itojun Exp $");
#endif
#endif /* not lint */
***************
*** 280,285 ****
--- 280,286 ----
choose_server(const char *name, const char *country)
{
static char *server;
+ char *nserver;
const char *qhead;
char *ep;
size_t len;
***************
*** 298,305 ****
} else if (isdigit((unsigned char)*(++qhead)))
return (ANICHOST);
len = strlen(qhead) + sizeof(QNICHOST_TAIL);
! if ((server = realloc(server, len)) == NULL)
err(1, "realloc");
(void)strlcpy(server, qhead, len);
(void)strlcat(server, QNICHOST_TAIL, len);
return (server);
--- 299,307 ----
} else if (isdigit((unsigned char)*(++qhead)))
return (ANICHOST);
len = strlen(qhead) + sizeof(QNICHOST_TAIL);
! if ((nserver = realloc(server, len)) == NULL)
err(1, "realloc");
+ server = nserver;
(void)strlcpy(server, qhead, len);
(void)strlcat(server, QNICHOST_TAIL, len);
return (server);