diff options
-rw-r--r-- | usr.bin/rs/rs.c | 16 | ||||
-rw-r--r-- | usr.bin/users/users.c | 16 |
2 files changed, 20 insertions, 12 deletions
diff --git a/usr.bin/rs/rs.c b/usr.bin/rs/rs.c index 9dabaf515f9..4572cc264e6 100644 --- a/usr.bin/rs/rs.c +++ b/usr.bin/rs/rs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rs.c,v 1.9 2003/06/10 22:20:50 deraadt Exp $ */ +/* $OpenBSD: rs.c,v 1.10 2003/10/16 16:57:14 tedu Exp $ */ /*- * Copyright (c) 1993 @@ -366,14 +366,18 @@ char ** getptrs(char **sp) { char **p; + int newsize, gap; - allocsize += allocsize; - p = (char **)realloc(elem, allocsize * sizeof(char *)); - if (p == (char **)0) + newsize = allocsize * 2; + p = realloc(elem, newsize * sizeof(char *)); + if (p == NULL) err(1, "no memory"); - sp += (p - elem); - endelem = (elem = p) + allocsize; + gap = p - elem; + elem = p; + allocsize = newsize; + sp += gap; + endelem = elem + allocsize; return(sp); } 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); |