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/rs/rs.c | |
parent | b875192e5911c0f2995a9eefdf4fe99406a8baad (diff) |
better realloc. ok deraadt@
Diffstat (limited to 'usr.bin/rs/rs.c')
-rw-r--r-- | usr.bin/rs/rs.c | 16 |
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); } |