diff options
author | Thomas Klausner <wiz@NetBSD.org> | 2017-05-19 10:22:44 +0200 |
---|---|---|
committer | Will Estes <westes575@gmail.com> | 2017-05-19 07:29:15 -0400 |
commit | 2b290d8ebdfa73b8f4665847fb689884eceee269 (patch) | |
tree | 89c70c5d43d8c609baea84ae0f41db4685e6efb7 /src/misc.c | |
parent | 3a70bac04ac4743d64c23d5f5a3df55494bf6050 (diff) |
scanner: Use reallocarr() when available.
NetBSD had a crash during build. Since the provided substitute for
reallocarray() wasn't working, use NetBSD's reallocarr(). Let
configure choose that function whenever it is available. Use
reallocarray if available. Still fallback if neither is available.
Fixes #219
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -142,7 +142,14 @@ void add_action (const char *new_text) void *allocate_array (int size, size_t element_size) { void *mem; -#if HAVE_REALLOCARRAY +#if HAVE_REALLOCARR + mem = NULL; + if (reallocarr(&mem, (size_t) size, element_size)) + flexfatal (_ + ("memory allocation failed in allocate_array()")); + + return mem; +#elif HAVE_REALLOCARRAY /* reallocarray has built-in overflow detection */ mem = reallocarray(NULL, (size_t) size, element_size); #else @@ -659,7 +666,12 @@ char *readable_form (int c) void *reallocate_array (void *array, int size, size_t element_size) { void *new_array; -#if HAVE_REALLOCARRAY +#if HAVE_REALLOCARR + if (reallocarr(&array, (size_t) size, element_size)) + flexfatal (_("attempt to increase array size failed")); + + return array; +#elif HAVE_REALLOCARRAY /* reallocarray has built-in overflow detection */ new_array = reallocarray(array, (size_t) size, element_size); #else |