diff options
author | Russ Allbery <eagle@eyrie.org> | 2014-07-11 20:18:41 -0700 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2014-07-11 22:38:49 -0700 |
commit | da0aba21779529d98436e42323fc12f702390969 (patch) | |
tree | 950e33ac99f2ff45303e939bf74f8bfbbb635215 /util/xmalloc.c | |
parent | 2971570d0e90bd166d87eff14e9e42c095c9f614 (diff) |
Update to rra-c-util 5.5 and C TAP Harness 3.1
Update to rra-c-util 5.5:
* Use Lancaster Consensus environment variables to control tests.
* Use calloc or reallocarray for protection against integer overflows.
* Suppress warnings from Kerberos headers in non-system paths.
* Assume calloc initializes pointers to NULL.
* Assume free(NULL) is properly ignored.
* Improve error handling in xasprintf and xvasprintf.
* Check the return status of snprintf and vsnprintf properly.
* Preserve errno if snprintf fails in vasprintf replacement.
Update to C TAP Harness 3.1:
* Reopen standard input to /dev/null when running a test list.
* Don't leak extraneous file descriptors to tests.
* Suppress lazy plans and test summaries if the test failed with bail.
* runtests now treats the command line as a list of tests by default.
* The full test executable path can now be passed to runtests -o.
* Improved harness output for tests with lazy plans.
* Improved harness output to a terminal for some abort cases.
* Flush harness output after each test even when not on a terminal.
Change-Id: I05161eb3d3be49a98f7762e876cb114da0c84e9a
Reviewed-on: https://gerrit.stanford.edu/1529
Reviewed-by: Russ Allbery <rra@stanford.edu>
Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'util/xmalloc.c')
-rw-r--r-- | util/xmalloc.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/util/xmalloc.c b/util/xmalloc.c index a78e31a..721447a 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -33,6 +33,10 @@ * allocation function will try its allocation again (calling the handler * again if it still fails). * + * xreallocarray behaves the same as the OpenBSD reallocarray function but for + * the same error checking, which in turn is the same as realloc but with + * calloc-style arguments and size overflow checking. + * * xstrndup behaves like xstrdup but only copies the given number of * characters. It allocates an additional byte over its second argument and * always nul-terminates the string. @@ -58,7 +62,7 @@ * The canonical version of this file is maintained in the rra-c-util package, * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>. * - * Copyright 2012 + * Copyright 2012, 2013, 2014 * The Board of Trustees of the Leland Stanford Junior University * Copyright (c) 2004, 2005, 2006 * by Internet Systems Consortium, Inc. ("ISC") @@ -84,8 +88,6 @@ #include <config.h> #include <portable/system.h> -#include <errno.h> - #include <util/messages.h> #include <util/xmalloc.h> @@ -96,8 +98,12 @@ void xmalloc_fail(const char *function, size_t size, const char *file, int line) { - sysdie("failed to %s %lu bytes at %s line %d", function, - (unsigned long) size, file, line); + if (size == 0) + sysdie("failed to format output with %s at %s line %d", function, + file, line); + else + sysdie("failed to %s %lu bytes at %s line %d", function, + (unsigned long) size, file, line); } /* Assign to this variable to choose a handler other than the default. */ @@ -150,6 +156,20 @@ x_realloc(void *p, size_t size, const char *file, int line) } +void * +x_reallocarray(void *p, size_t n, size_t size, const char *file, int line) +{ + void *newp; + + newp = reallocarray(p, n, size); + while (newp == NULL && size > 0 && n > 0) { + (*xmalloc_error_handler)("reallocarray", n * size, file, line); + newp = reallocarray(p, n, size); + } + return newp; +} + + char * x_strdup(const char *s, const char *file, int line) { @@ -208,7 +228,8 @@ x_vasprintf(char **strp, const char *fmt, va_list args, const char *file, va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); - (*xmalloc_error_handler)("vasprintf", status + 1, file, line); + status = (status < 0) ? 0 : status + 1; + (*xmalloc_error_handler)("vasprintf", status, file, line); va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); @@ -231,7 +252,8 @@ x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); - (*xmalloc_error_handler)("asprintf", status + 1, file, line); + status = (status < 0) ? 0 : status + 1; + (*xmalloc_error_handler)("asprintf", status, file, line); va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); @@ -252,7 +274,8 @@ x_asprintf(char **strp, const char *fmt, ...) va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); - (*xmalloc_error_handler)("asprintf", status + 1, __FILE__, __LINE__); + status = (status < 0) ? 0 : status + 1; + (*xmalloc_error_handler)("asprintf", status, __FILE__, __LINE__); va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); |