diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-10-16 16:57:38 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-10-16 16:57:38 +0000 |
commit | 233fac375b1bbd3ad1a7fb89dfc40fd98e386bdb (patch) | |
tree | f3f832089552b3d28dd8260373ae4d99ee86ecad /usr.bin/users/users.c | |
parent | b875192e5911c0f2995a9eefdf4fe99406a8baad (diff) |
better realloc. ok deraadt@
Diffstat (limited to 'usr.bin/users/users.c')
-rw-r--r-- | usr.bin/users/users.c | 16 |
1 files changed, 10 insertions, 6 deletions
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 <sys/types.h> @@ -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); |