diff options
author | Russ Allbery <rra@stanford.edu> | 2013-02-27 14:25:37 -0800 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2013-02-27 16:52:32 -0800 |
commit | 234e3805c524a7432caed8be328df6e2fbfe9afb (patch) | |
tree | d40473e103f8cfacec000959c2ae3ea83e8e86b2 /util/xmalloc.c | |
parent | 7a572127a7305a17bf84c26e66e65ab37f66b77d (diff) |
Update to rra-c-util 4.8 and C TAP Harness 1.12
Update to rra-c-util 4.8:
* Look for krb5-config in /usr/kerberos/bin after the user's PATH.
* Kerberos library probing fixes without transitive shared libraries.
* Fix Autoconf warnings when probing for AIX's bundled Kerberos.
* Avoid using krb5-config if --with-{krb5,gssapi}-{include,lib} given.
* Correctly remove -I/usr/include from Kerberos and GSS-API flags.
* Build on systems where krb5/krb5.h exists but krb5.h does not.
* Pass --deps to krb5-config unless --enable-reduced-depends was used.
* Do not use krb5-config results unless gssapi is supported.
* Fix probing for Heimdal's libroken to work with older versions.
* Update warning flags for GCC 4.6.1.
* Update utility library and test suite for newer GCC warnings.
* Fix broken GCC attribute markers causing compilation problems.
* Suppress warnings on compilers that support gcc's __attribute__.
* Add notices to all files copied over from rra-c-util.
* Fix warnings when reporting memory allocation failure in messages.c.
* Fix message utility library compiler warnings on 64-bit systems.
* Include strings.h for additional POSIX functions where found.
* Use an atexit handler to clean up after Kerberos tests.
* Kerberos test configuration now goes in tests/config.
* The principal of the test keytab is determined automatically.
* Simplify the test suite calls for Kerberos and remctl tests.
* Check for a missing ssize_t.
* Improve the xstrndup utility function.
* Checked asprintf variants are now void functions and cannot fail.
* Fix use of long long in portable/mkstemp.c.
* Fix test suite portability to Solaris.
* Substantial improvements to the POD syntax and spelling checks.
Update to C TAP Harness 1.12:
* Fix compliation of runtests with more aggressive warnings.
* Add a more complete usage message and a -h command-line flag.
* Flush stderr before printing output from tests.
* Better handle running shell tests without BUILD and SOURCE set.
* Fix runtests to honor -s even if BUILD and -b aren't given.
* runtests now frees all allocated resources on exit.
* Only use feature-test macros when requested or built with gcc -ansi.
* Drop is_double from the C TAP library to avoid requiring -lm.
* Avoid using local in the shell libtap.sh library.
* Suppress warnings on compilers that support gcc's __attribute__.
Change-Id: I394294d5486ac1ce265c7713bec71a148aaaf1ce
Reviewed-on: https://gerrit.stanford.edu/841
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 | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/util/xmalloc.c b/util/xmalloc.c index 4e05f96..a78e31a 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -55,12 +55,30 @@ * header file defines macros named xmalloc, etc. that pass the file name and * line number to these functions. * + * 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 + * The Board of Trustees of the Leland Stanford Junior University * Copyright (c) 2004, 2005, 2006 * by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, * 2002, 2003 by The Internet Software Consortium and Rich Salz * - * See LICENSE for licensing terms. + * This code is derived from software contributed to the Internet Software + * Consortium by Rich Salz. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ #include <config.h> @@ -149,23 +167,34 @@ x_strdup(const char *s, const char *file, int line) } +/* + * Avoid using the system strndup function since it may not exist (on Mac OS + * X, for example), and there's no need to introduce another portability + * requirement. + */ char * x_strndup(const char *s, size_t size, const char *file, int line) { - char *p; + const char *p; + size_t length; + char *copy; - p = malloc(size + 1); - while (p == NULL) { - (*xmalloc_error_handler)("strndup", size + 1, file, line); - p = malloc(size + 1); + /* Don't assume that the source string is nul-terminated. */ + for (p = s; (size_t) (p - s) < size && *p != '\0'; p++) + ; + length = p - s; + copy = malloc(length + 1); + while (copy == NULL) { + (*xmalloc_error_handler)("strndup", length + 1, file, line); + copy = malloc(length + 1); } - memcpy(p, s, size); - p[size] = '\0'; - return p; + memcpy(copy, s, length); + copy[length] = '\0'; + return copy; } -int +void x_vasprintf(char **strp, const char *fmt, va_list args, const char *file, int line) { @@ -175,7 +204,7 @@ x_vasprintf(char **strp, const char *fmt, va_list args, const char *file, va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); - while (status < 0 && errno == ENOMEM) { + while (status < 0) { va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); @@ -184,12 +213,11 @@ x_vasprintf(char **strp, const char *fmt, va_list args, const char *file, status = vasprintf(strp, fmt, args_copy); va_end(args_copy); } - return status; } #if HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS -int +void x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) { va_list args, args_copy; @@ -199,7 +227,7 @@ x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); - while (status < 0 && errno == ENOMEM) { + while (status < 0) { va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); @@ -208,10 +236,9 @@ x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) status = vasprintf(strp, fmt, args_copy); va_end(args_copy); } - return status; } #else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */ -int +void x_asprintf(char **strp, const char *fmt, ...) { va_list args, args_copy; @@ -221,7 +248,7 @@ x_asprintf(char **strp, const char *fmt, ...) va_copy(args_copy, args); status = vasprintf(strp, fmt, args_copy); va_end(args_copy); - while (status < 0 && errno == ENOMEM) { + while (status < 0) { va_copy(args_copy, args); status = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); @@ -230,6 +257,5 @@ x_asprintf(char **strp, const char *fmt, ...) status = vasprintf(strp, fmt, args_copy); va_end(args_copy); } - return status; } #endif /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */ |