summaryrefslogtreecommitdiff
path: root/usr.bin/rs/rs.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2003-10-16 16:57:38 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2003-10-16 16:57:38 +0000
commit233fac375b1bbd3ad1a7fb89dfc40fd98e386bdb (patch)
treef3f832089552b3d28dd8260373ae4d99ee86ecad /usr.bin/rs/rs.c
parentb875192e5911c0f2995a9eefdf4fe99406a8baad (diff)
better realloc. ok deraadt@
Diffstat (limited to 'usr.bin/rs/rs.c')
-rw-r--r--usr.bin/rs/rs.c16
1 files changed, 10 insertions, 6 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);
}