From 233fac375b1bbd3ad1a7fb89dfc40fd98e386bdb Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 16 Oct 2003 16:57:38 +0000 Subject: better realloc. ok deraadt@ --- usr.bin/users/users.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'usr.bin/users/users.c') diff --git a/usr.bin/users/users.c b/usr.bin/users/users.c index 60e350e1b84..2a68ef2451d 100644 --- a/usr.bin/users/users.c +++ b/usr.bin/users/users.c @@ -1,4 +1,4 @@ -/* $OpenBSD: users.c,v 1.7 2003/06/03 02:56:21 millert Exp $ */ +/* $OpenBSD: users.c,v 1.8 2003/10/16 16:57:37 tedu Exp $ */ /* $NetBSD: users.c,v 1.5 1994/12/20 15:58:19 jtc Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)users.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: users.c,v 1.7 2003/06/03 02:56:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: users.c,v 1.8 2003/10/16 16:57:37 tedu Exp $"; #endif /* not lint */ #include @@ -82,14 +82,18 @@ main(int argc, char *argv[]) while (fread((char *)&utmp, sizeof(utmp), 1, stdin) == 1) { if (*utmp.ut_name) { if (ncnt >= nmax) { - nmax += 32; - names = realloc(names, - sizeof (*names) * nmax); + size_t newmax = nmax + 32; + namebuf *newnames; - if (!names) { + newnames = realloc(names, + sizeof(*names) * newmax); + + if (newnames == NULL) { err(1, NULL); /* NOTREACHED */ } + names = newnames; + nmax = newmax; } (void)strncpy(names[ncnt], utmp.ut_name, UT_NAMESIZE); -- cgit v1.2.3