summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2003-09-28 19:29:34 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2003-09-28 19:29:34 +0000
commitcc46350b72fb3d36e4d2408ded0d48e6fb4761ea (patch)
tree3b118f7e8d58998544eef18f3aa144f60b4861b8 /usr.bin
parente370851f45a13abfdbb4e67bec5c468d138fa209 (diff)
realloc cleanup
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dc/inout.c11
-rw-r--r--usr.bin/dc/stack.c14
2 files changed, 13 insertions, 12 deletions
diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c
index b3e8d85243a..8326bb910d7 100644
--- a/usr.bin/dc/inout.c
+++ b/usr.bin/dc/inout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inout.c,v 1.3 2003/09/19 19:06:29 deraadt Exp $ */
+/* $OpenBSD: inout.c,v 1.4 2003/09/28 19:29:32 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: inout.c,v 1.3 2003/09/19 19:06:29 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: inout.c,v 1.4 2003/09/28 19:29:32 otto Exp $";
#endif /* not lint */
#include <ssl/ssl.h>
@@ -214,7 +214,7 @@ readnumber(struct source *src, u_int base)
char *
read_string(struct source *src)
{
- int count, i, sz, ch;
+ int count, i, sz, new_sz, ch;
char *p;
count = 1;
@@ -230,8 +230,9 @@ read_string(struct source *src)
if (count == 0)
break;
if (i == sz) {
- sz *= 2;
- p = brealloc(p, sz + 1);
+ new_sz = sz * 2;
+ p = brealloc(p, new_sz + 1);
+ sz = new_sz;
}
p[i++] = ch;
}
diff --git a/usr.bin/dc/stack.c b/usr.bin/dc/stack.c
index 5dd9e8e4194..c35fb6a7fbb 100644
--- a/usr.bin/dc/stack.c
+++ b/usr.bin/dc/stack.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stack.c,v 1.2 2003/09/19 19:00:36 deraadt Exp $ */
+/* $OpenBSD: stack.c,v 1.3 2003/09/28 19:29:33 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: stack.c,v 1.2 2003/09/19 19:00:36 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: stack.c,v 1.3 2003/09/28 19:29:33 otto Exp $";
#endif /* not lint */
#include <err.h>
@@ -119,15 +119,15 @@ stack_dup(struct stack *stack)
static void
stack_grow(struct stack *stack)
{
- int old_size, i;
+ int new_size, i;
if (++stack->sp == stack->size) {
- old_size = stack->size;
- stack->size *= 2;
+ new_size = stack->size * 2 + 1;
stack->stack = brealloc(stack->stack,
- ++stack->size * sizeof(*stack->stack));
- for (i = old_size; i < stack->size; i++)
+ new_size * sizeof(*stack->stack));
+ for (i = stack->size; i < new_size; i++)
stack->stack[i].array = NULL;
+ stack->size = new_size;
}
}