aboutsummaryrefslogtreecommitdiff
path: root/portable
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2020-05-17 17:05:30 -0700
committerRuss Allbery <eagle@eyrie.org>2020-05-17 17:05:30 -0700
commitc138111a3c27863308b6552a5527a9e821a3dc11 (patch)
treefe3c16462bf0213708f20d251a63e5b9bbf2d23f /portable
parentccfbd34d597318215b979338c4cb5d7e4a3f0d6f (diff)
Update to rra-c-util 8.2 and C TAP Harness 4.7
Update to rra-c-util 8.2: * Implement explicit_bzero with memset if it is not available. * Reformat all C source using clang-format 10. * Work around Test::Strict not skipping .git directories. * Fix warnings with perltidy 20190601 and Perl::Critic 1.134. * Fix warnings with Clang 10, GCC 10, and the Clang static analyzer. Update to C TAP Harness 4.7: * Fix warnings with GCC 10. * Reformat all C source using clang-format 10. * Fixed malloc error checking in bstrndup.
Diffstat (limited to 'portable')
-rw-r--r--portable/asprintf.c8
-rw-r--r--portable/krb5-extra.c38
-rw-r--r--portable/krb5-profile.c2
-rw-r--r--portable/krb5.h30
-rw-r--r--portable/macros.h24
-rw-r--r--portable/mkstemp.c6
-rw-r--r--portable/reallocarray.c4
-rw-r--r--portable/setenv.c4
-rw-r--r--portable/snprintf.c35
-rw-r--r--portable/stdbool.h34
-rw-r--r--portable/system.h32
-rw-r--r--portable/uio.h2
12 files changed, 125 insertions, 94 deletions
diff --git a/portable/asprintf.c b/portable/asprintf.c
index aef3639..0451a03 100644
--- a/portable/asprintf.c
+++ b/portable/asprintf.c
@@ -31,10 +31,10 @@
* with the system versions.
*/
#if TESTING
-# undef asprintf
-# undef vasprintf
-# define asprintf test_asprintf
-# define vasprintf test_vasprintf
+# undef asprintf
+# undef vasprintf
+# define asprintf test_asprintf
+# define vasprintf test_vasprintf
int test_asprintf(char **, const char *, ...)
__attribute__((__format__(printf, 2, 3)));
int test_vasprintf(char **, const char *, va_list)
diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c
index 9de8e65..3632f8b 100644
--- a/portable/krb5-extra.c
+++ b/portable/krb5-extra.c
@@ -31,17 +31,17 @@
/* Figure out what header files to include for error reporting. */
#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)
-# if !defined(HAVE_KRB5_GET_ERROR_STRING)
-# if defined(HAVE_IBM_SVC_KRB5_SVC_H)
-# include <ibm_svc/krb5_svc.h>
-# elif defined(HAVE_ET_COM_ERR_H)
-# include <et/com_err.h>
-# elif defined(HAVE_KERBEROSV5_COM_ERR_H)
-# include <kerberosv5/com_err.h>
-# else
-# include <com_err.h>
-# endif
-# endif
+# if !defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_IBM_SVC_KRB5_SVC_H)
+# include <ibm_svc/krb5_svc.h>
+# elif defined(HAVE_ET_COM_ERR_H)
+# include <et/com_err.h>
+# elif defined(HAVE_KERBEROSV5_COM_ERR_H)
+# include <kerberosv5/com_err.h>
+# else
+# include <com_err.h>
+# endif
+# endif
#endif
/* Used for unused parameters to silence gcc warnings. */
@@ -69,15 +69,15 @@ krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED)
{
const char *msg;
-# if defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_KRB5_GET_ERROR_STRING)
msg = krb5_get_error_string(ctx);
-# elif defined(HAVE_KRB5_GET_ERR_TEXT)
+# elif defined(HAVE_KRB5_GET_ERR_TEXT)
msg = krb5_get_err_text(ctx, code);
-# elif defined(HAVE_KRB5_SVC_GET_MSG)
+# elif defined(HAVE_KRB5_SVC_GET_MSG)
krb5_svc_get_msg(code, (char **) &msg);
-# else
+# else
msg = error_message(code);
-# endif
+# endif
if (msg == NULL)
return error_unknown;
else
@@ -100,11 +100,11 @@ krb5_free_error_message(krb5_context ctx UNUSED, const char *msg)
{
if (msg == error_unknown)
return;
-# if defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_KRB5_GET_ERROR_STRING)
krb5_free_error_string(ctx, (char *) msg);
-# elif defined(HAVE_KRB5_SVC_GET_MSG)
+# elif defined(HAVE_KRB5_SVC_GET_MSG)
krb5_free_string(ctx, (char *) msg);
-# endif
+# endif
}
#endif /* !HAVE_KRB5_FREE_ERROR_MESSAGE */
diff --git a/portable/krb5-profile.c b/portable/krb5-profile.c
index f4d4652..582e7ac 100644
--- a/portable/krb5-profile.c
+++ b/portable/krb5-profile.c
@@ -218,7 +218,7 @@ krb5_appdefault_string(krb5_context context, const char *appname, const krb5_dat
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Individual source code files are copyright MIT, Cygnus Support,
* OpenVision, Oracle, Sun Soft, FundsXpress, and others.
diff --git a/portable/krb5.h b/portable/krb5.h
index d8884a7..53092e3 100644
--- a/portable/krb5.h
+++ b/portable/krb5.h
@@ -20,7 +20,7 @@
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2015, 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015, 2017, 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2010-2014
* The Board of Trustees of the Leland Stanford Junior University
*
@@ -40,16 +40,16 @@
* stripped-down version of config.h with a different name.
*/
#ifndef CONFIG_H_INCLUDED
-# include <config.h>
+# include <config.h>
#endif
#include <portable/macros.h>
#if defined(HAVE_KRB5_H)
-# include <krb5.h>
+# include <krb5.h>
#elif defined(HAVE_KERBEROSV5_KRB5_H)
-# include <kerberosv5/krb5.h>
+# include <kerberosv5/krb5.h>
#else
-# include <krb5/krb5.h>
+# include <krb5/krb5.h>
#endif
#include <stdlib.h>
@@ -76,7 +76,12 @@ void krb5_appdefault_string(krb5_context, const char *, const krb5_data *,
* Kerberos library. Use krb5_xfree instead.
*/
#ifndef HAVE_KRB5_FREE_DEFAULT_REALM
-# define krb5_free_default_realm(c, r) krb5_xfree(r)
+# define krb5_free_default_realm(c, r) krb5_xfree(r)
+#endif
+
+/* Heimdal: krb5_xfree, MIT: krb5_free_unparsed_name. */
+#ifdef HAVE_KRB5_XFREE
+# define krb5_free_unparsed_name(c, p) krb5_xfree(p)
#endif
/*
@@ -105,16 +110,17 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context,
krb5_get_init_creds_opt **);
#endif
#ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE
-# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS
-# define krb5_get_init_creds_opt_free(c, o) krb5_get_init_creds_opt_free(o)
-# endif
+# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS
+# define krb5_get_init_creds_opt_free(c, o) \
+ krb5_get_init_creds_opt_free(o)
+# endif
#else
-# define krb5_get_init_creds_opt_free(c, o) free(o)
+# define krb5_get_init_creds_opt_free(c, o) free(o)
#endif
/* Heimdal-specific. */
#ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_DEFAULT_FLAGS
-# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */
+# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */
#endif
/*
@@ -123,7 +129,7 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context,
* present in older MIT Kerberos libraries but not prototyped.
*/
#if !HAVE_DECL_KRB5_KT_FREE_ENTRY
-# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e))
+# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e))
#endif
/*
diff --git a/portable/macros.h b/portable/macros.h
index 586b07e..5d77fb7 100644
--- a/portable/macros.h
+++ b/portable/macros.h
@@ -26,9 +26,9 @@
* (to avoid confusion with other macros).
*/
#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(spec) /* empty */
-# endif
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __attribute__(spec) /* empty */
+# endif
#endif
/*
@@ -39,10 +39,10 @@
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
-# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
- && !defined(__clang__)
-# define __alloc_size__(spec, args...) /* empty */
-# endif
+# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
+ && !defined(__clang__)
+# define __alloc_size__(spec, args...) /* empty */
+# endif
#endif
/*
@@ -52,7 +52,7 @@
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
-# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wattributes"
#endif
/*
@@ -62,11 +62,11 @@
#undef BEGIN_DECLS
#undef END_DECLS
#ifdef __cplusplus
-# define BEGIN_DECLS extern "C" {
-# define END_DECLS }
+# define BEGIN_DECLS extern "C" {
+# define END_DECLS }
#else
-# define BEGIN_DECLS /* empty */
-# define END_DECLS /* empty */
+# define BEGIN_DECLS /* empty */
+# define END_DECLS /* empty */
#endif
#endif /* !PORTABLE_MACROS_H */
diff --git a/portable/mkstemp.c b/portable/mkstemp.c
index 9e3bba1..ebaefc1 100644
--- a/portable/mkstemp.c
+++ b/portable/mkstemp.c
@@ -25,7 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+# include <sys/time.h>
#endif
#include <time.h>
@@ -35,8 +35,8 @@
* another name.
*/
#if TESTING
-# undef mkstemp
-# define mkstemp test_mkstemp
+# undef mkstemp
+# define mkstemp test_mkstemp
int test_mkstemp(char *);
#endif
diff --git a/portable/reallocarray.c b/portable/reallocarray.c
index 3c6ea37..635041e 100644
--- a/portable/reallocarray.c
+++ b/portable/reallocarray.c
@@ -33,8 +33,8 @@
* it to another name.
*/
#if TESTING
-# undef reallocarray
-# define reallocarray test_reallocarray
+# undef reallocarray
+# define reallocarray test_reallocarray
void *test_reallocarray(void *, size_t, size_t);
#endif
diff --git a/portable/setenv.c b/portable/setenv.c
index afa8930..b2cc905 100644
--- a/portable/setenv.c
+++ b/portable/setenv.c
@@ -28,8 +28,8 @@
* the system version.
*/
#if TESTING
-# undef setenv
-# define setenv test_setenv
+# undef setenv
+# define setenv test_setenv
int test_setenv(const char *, const char *, int);
#endif
diff --git a/portable/snprintf.c b/portable/snprintf.c
index a42ef3b..a22e4e4 100644
--- a/portable/snprintf.c
+++ b/portable/snprintf.c
@@ -25,6 +25,28 @@
# define vsnprintf test_vsnprintf
#endif
+/*
+ * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
+ * could you use the __format__ form of the attributes, which is what we use
+ * (to avoid confusion with other macros).
+ */
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __attribute__(spec) /* empty */
+# endif
+#endif
+
+/*
+ * Older Clang doesn't support __attribute__((fallthrough)) properly and
+ * complains about the empty statement that it is decorating. Suppress that
+ * warning. Also suppress warnings about unknown attributes to handle older
+ * Clang versions.
+ */
+#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
+# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wmissing-declarations"
+#endif
+
/* Specific to rra-c-util, but only when debugging is enabled. */
#ifdef DEBUG_SNPRINTF
# include <util/messages.h>
@@ -64,7 +86,7 @@
* probably requires libm on most operating systems. Don't yet
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
* was pretty badly broken, it just wasn't being exercised in ways
- * which showed it, so that's been fixed. Also, formated the code
+ * which showed it, so that's been fixed. Also, formatted the code
* to mutt conventions, and removed dead code left over from the
* original. Also, there is now a builtin-test, just compile with:
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
@@ -366,7 +388,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
break;
case 'X':
flags |= DP_F_UP;
- /* fallthrough */
+ __attribute__((fallthrough));
+ /* fall through */
case 'x':
flags |= DP_F_UNSIGNED;
if (cflags == DP_C_SHORT)
@@ -388,7 +411,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
break;
case 'E':
flags |= DP_F_UP;
- /* fallthrough */
+ __attribute__((fallthrough));
+ /* fall through */
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
@@ -398,7 +422,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
break;
case 'G':
flags |= DP_F_UP;
- /* fallthrough */
+ __attribute__((fallthrough));
+ /* fall through */
case 'g':
flags |= DP_F_FP_G;
if (cflags == DP_C_LDOUBLE)
@@ -714,7 +739,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
if (intpart != 0)
{
/* For each digit of INTPART, print one less fractional digit. */
- LLONG temp = intpart;
+ LLONG temp;
for (temp = intpart; temp != 0; temp /= 10)
--max;
if (max < 0)
diff --git a/portable/stdbool.h b/portable/stdbool.h
index 3efe4c9..749052a 100644
--- a/portable/stdbool.h
+++ b/portable/stdbool.h
@@ -28,28 +28,28 @@
* stripped-down version of config.h with a different name.
*/
#ifndef CONFIG_H_INCLUDED
-# include <config.h>
+# include <config.h>
#endif
#if HAVE_STDBOOL_H
-# include <stdbool.h>
+# include <stdbool.h>
#else
-# if HAVE__BOOL
-# define bool _Bool
-# else
-# ifdef __cplusplus
+# if HAVE__BOOL
+# define bool _Bool
+# else
+# ifdef __cplusplus
typedef bool _Bool;
-# elif _WIN32
-# include <windef.h>
-# define bool BOOL
-# else
+# elif _WIN32
+# include <windef.h>
+# define bool BOOL
+# else
typedef unsigned char _Bool;
-# define bool _Bool
-# endif
-# endif
-# define false 0
-# define true 1
-# define __bool_true_false_are_defined 1
+# define bool _Bool
+# endif
+# endif
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
#endif
/*
@@ -57,7 +57,7 @@ typedef unsigned char _Bool;
* fail. Only of interest for programs that also include Perl headers.
*/
#ifndef HAS_BOOL
-# define HAS_BOOL 1
+# define HAS_BOOL 1
#endif
#endif /* !PORTABLE_STDBOOL_H */
diff --git a/portable/system.h b/portable/system.h
index 6fe4928..3d62b6f 100644
--- a/portable/system.h
+++ b/portable/system.h
@@ -25,7 +25,7 @@
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2014, 2016, 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014, 2016, 2018, 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2006-2011, 2013-2014
* The Board of Trustees of the Leland Stanford Junior University
*
@@ -48,28 +48,28 @@
/* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
#if HAVE_INTTYPES_H
-# include <inttypes.h>
+# include <inttypes.h>
#endif
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#if HAVE_STDINT_H
-# include <stdint.h>
+# include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_STRINGS_H
-# include <strings.h>
+# include <strings.h>
#endif
#include <sys/types.h>
#if HAVE_UNISTD_H
-# include <unistd.h>
+# include <unistd.h>
#endif
/* SCO OpenServer gets int32_t from here. */
#if HAVE_SYS_BITYPES_H
-# include <sys/bitypes.h>
+# include <sys/bitypes.h>
#endif
/* Get the bool type. */
@@ -77,12 +77,12 @@
/* In case uint32_t and associated limits weren't defined. */
#ifndef UINT32_MAX
-# define UINT32_MAX 4294967295UL
+# define UINT32_MAX 4294967295UL
#endif
/* Windows provides snprintf under a different name. */
#ifdef _WIN32
-# define snprintf _snprintf
+# define snprintf _snprintf
#endif
/* Windows does not define ssize_t. */
@@ -95,9 +95,9 @@ typedef ptrdiff_t ssize_t;
* been defined, all the rest almost certainly have.
*/
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-# define STDOUT_FILENO 1
-# define STDERR_FILENO 2
+# define STDIN_FILENO 0
+# define STDOUT_FILENO 1
+# define STDERR_FILENO 2
#endif
/*
@@ -105,11 +105,11 @@ typedef ptrdiff_t ssize_t;
* Autoconf manual, memcpy is a generally portable fallback.
*/
#ifndef va_copy
-# ifdef __va_copy
-# define va_copy(d, s) __va_copy((d), (s))
-# else
-# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
-# endif
+# ifdef __va_copy
+# define va_copy(d, s) __va_copy((d), (s))
+# else
+# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
+# endif
#endif
BEGIN_DECLS
diff --git a/portable/uio.h b/portable/uio.h
index 8635d18..e759d30 100644
--- a/portable/uio.h
+++ b/portable/uio.h
@@ -27,7 +27,7 @@
/* remctl.h provides its own definition of this struct on Windows. */
#if defined(HAVE_SYS_UIO_H)
-# include <sys/uio.h>
+# include <sys/uio.h>
#elif !defined(REMCTL_H)
struct iovec {
void *iov_base;