aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-03-05 16:10:35 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-03-05 16:10:35 +0000
commit63433bc937051f84486b603e9803597db68f796b (patch)
tree3b85912a1a98333288adba4e1610a49447f3a2f2 /usr.bin
parentd457839bc81ca7d922661f349b8b9a0e3fe13238 (diff)
downloadsrc-63433bc937051f84486b603e9803597db68f796b.tar.gz
src-63433bc937051f84486b603e9803597db68f796b.zip
bc/dc/patch: make some use of reallocarray(3).
reallocarray(3) is a non portable extension from OpenBSD. Given that it is already in FreeBSD, make easier future merges by adopting in some cases where the code has some shared heritage with OpenBSD. Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=314704
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/bc/bc.y6
-rw-r--r--usr.bin/dc/bcode.c4
-rw-r--r--usr.bin/dc/extern.h4
-rw-r--r--usr.bin/dc/inout.c4
-rw-r--r--usr.bin/dc/mem.c6
-rw-r--r--usr.bin/dc/stack.c8
-rw-r--r--usr.bin/patch/inp.c4
7 files changed, 18 insertions, 18 deletions
diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y
index 17f308edf690..50ac130b461c 100644
--- a/usr.bin/bc/bc.y
+++ b/usr.bin/bc/bc.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: bc.y,v 1.44 2013/11/20 21:33:54 deraadt Exp $ */
+/* $OpenBSD: bc.y,v 1.46 2014/10/14 15:35:18 deraadt Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -771,7 +771,7 @@ grow(void)
if (current == instr_sz) {
newsize = instr_sz * 2 + 1;
- p = realloc(instructions, newsize * sizeof(*p));
+ p = reallocarray(instructions, newsize, sizeof(*p));
if (p == NULL) {
free(instructions);
err(1, NULL);
@@ -1132,7 +1132,7 @@ main(int argc, char *argv[])
init();
setvbuf(stdout, NULL, _IOLBF, 0);
- sargv = malloc(argc * sizeof(char *));
+ sargv = reallocarray(NULL, argc, sizeof(char *));
if (sargv == NULL)
err(1, NULL);
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index e6a980e4ac23..fc83282b4e01 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcode.c,v 1.45 2012/11/07 11:06:14 otto Exp $ */
+/* $OpenBSD: bcode.c,v 1.46 2014/10/08 03:59:56 doug Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -1709,7 +1709,7 @@ eval_string(char *p)
if (bmachine.readsp == bmachine.readstack_sz - 1) {
size_t newsz = bmachine.readstack_sz * 2;
struct source *stack;
- stack = realloc(bmachine.readstack, newsz *
+ stack = reallocarray(bmachine.readstack, newsz,
sizeof(struct source));
if (stack == NULL)
err(1, "recursion too deep");
diff --git a/usr.bin/dc/extern.h b/usr.bin/dc/extern.h
index 4abf06355a3a..477fcea9eb61 100644
--- a/usr.bin/dc/extern.h
+++ b/usr.bin/dc/extern.h
@@ -1,5 +1,5 @@
/* $FreeBSD$ */
-/* $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 <otto@drijf.net>
@@ -35,7 +35,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 740fb35bae7f..bd675f51023a 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 <otto@drijf.net>
@@ -261,7 +261,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 78fb429e2604..e83a70ad5ec8 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 <otto@drijf.net>
@@ -72,11 +72,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 33082c77ec04..ba7c7e4a589b 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 <otto@drijf.net>
@@ -139,8 +139,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;
}
}
@@ -313,7 +313,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;
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 19536da0f5f8..2c955d0c8377 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -23,7 +23,7 @@
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
* behaviour
*
- * $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $
+ * $OpenBSD: inp.c,v 1.44 2015/07/26 14:32:19 millert Exp $
* $FreeBSD$
*/
@@ -118,7 +118,7 @@ reallocate_lines(size_t *lines_allocated)
size_t new_size;
new_size = *lines_allocated * 3 / 2;
- p = realloc(i_ptr, (new_size + 2) * sizeof(char *));
+ p = reallocarray(i_ptr, new_size + 2, sizeof(char *));
if (p == NULL) { /* shucks, it was a near thing */
munmap(i_womp, i_size);
i_womp = NULL;