From 4c359b74cbe39f232c2792fc1a2347b7be9c0e79 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Mon, 1 Dec 2014 13:13:01 +0000 Subject: more opportunity to use reallocarray(); ok otto --- usr.bin/dc/extern.h | 4 ++-- usr.bin/dc/inout.c | 4 ++-- usr.bin/dc/mem.c | 6 +++--- usr.bin/dc/stack.c | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/dc/extern.h b/usr.bin/dc/extern.h index b179d2e0e46..9642dfc5ddf 100644 --- a/usr.bin/dc/extern.h +++ b/usr.bin/dc/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.3 2006/01/16 08:09:25 otto Exp $ */ +/* $OpenBSD: extern.h,v 1.4 2014/12/01 13:13:00 deraadt Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -34,7 +34,7 @@ struct number *new_number(void); void free_number(struct number *); struct number *dup_number(const struct number *); void *bmalloc(size_t); -void *brealloc(void *, size_t); +void *breallocarray(void *, size_t, size_t); char *bstrdup(const char *p); void bn_check(int); void bn_checkp(const void *); diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c index 00832763f46..a96b6717ced 100644 --- a/usr.bin/dc/inout.c +++ b/usr.bin/dc/inout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inout.c,v 1.17 2012/11/07 11:06:14 otto Exp $ */ +/* $OpenBSD: inout.c,v 1.18 2014/12/01 13:13:00 deraadt Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -256,7 +256,7 @@ read_string(struct source *src) escape = false; if (i == sz) { new_sz = sz * 2; - p = brealloc(p, new_sz + 1); + p = breallocarray(p, 1, new_sz + 1); sz = new_sz; } p[i++] = ch; diff --git a/usr.bin/dc/mem.c b/usr.bin/dc/mem.c index d39603697fa..189467317d8 100644 --- a/usr.bin/dc/mem.c +++ b/usr.bin/dc/mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mem.c,v 1.5 2009/10/27 23:59:37 deraadt Exp $ */ +/* $OpenBSD: mem.c,v 1.6 2014/12/01 13:13:00 deraadt Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -68,11 +68,11 @@ bmalloc(size_t sz) } void * -brealloc(void *p, size_t sz) +breallocarray(void *p, size_t nmemb, size_t size) { void *q; - q = realloc(p, sz); + q = reallocarray(p, nmemb, size); if (q == NULL) err(1, NULL); return q; diff --git a/usr.bin/dc/stack.c b/usr.bin/dc/stack.c index 41309681324..1198f7b0bdd 100644 --- a/usr.bin/dc/stack.c +++ b/usr.bin/dc/stack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack.c,v 1.12 2014/11/26 15:05:51 otto Exp $ */ +/* $OpenBSD: stack.c,v 1.13 2014/12/01 13:13:00 deraadt Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -133,8 +133,8 @@ stack_grow(struct stack *stack) if (++stack->sp == stack->size) { new_size = stack->size * 2 + 1; - stack->stack = brealloc(stack->stack, - new_size * sizeof(*stack->stack)); + stack->stack = breallocarray(stack->stack, + new_size, sizeof(*stack->stack)); stack->size = new_size; } } @@ -303,7 +303,7 @@ array_grow(struct array *array, size_t newsize) { size_t i; - array->data = brealloc(array->data, newsize * sizeof(*array->data)); + array->data = breallocarray(array->data, newsize, sizeof(*array->data)); for (i = array->size; i < newsize; i++) { array->data[i].type = BCODE_NONE; array->data[i].array = NULL; -- cgit v1.2.3