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
This commit is contained in:
parent
b3689d3c04
commit
a2e1f1f7a7
@ -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);
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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 *);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user