INN commit: branches/2.6 (62 files)

INN Commit rra at isc.org
Thu Nov 12 20:19:43 UTC 2020


    Date: Thursday, November 12, 2020 @ 12:19:41
  Author: iulius
Revision: 10396

Update to latest rra-c-util and C TAP Harness upstream versions

Modified:
  branches/2.6/include/clibrary.h
  branches/2.6/include/inn/buffer.h
  branches/2.6/include/inn/fdflag.h
  branches/2.6/include/inn/network-innbind.h
  branches/2.6/include/inn/network.h
  branches/2.6/include/inn/vector.h
  branches/2.6/include/inn/xmalloc.h
  branches/2.6/include/portable/getaddrinfo.h
  branches/2.6/include/portable/getnameinfo.h
  branches/2.6/include/portable/macros.h
  branches/2.6/include/portable/socket-unix.h
  branches/2.6/include/portable/socket.h
  branches/2.6/include/portable/stdbool.h
  branches/2.6/include/portable/uio.h
  branches/2.6/lib/asprintf.c
  branches/2.6/lib/buffer.c
  branches/2.6/lib/fdflag.c
  branches/2.6/lib/getaddrinfo.c
  branches/2.6/lib/getnameinfo.c
  branches/2.6/lib/inet_aton.c
  branches/2.6/lib/inet_ntoa.c
  branches/2.6/lib/inet_ntop.c
  branches/2.6/lib/messages.c
  branches/2.6/lib/mkstemp.c
  branches/2.6/lib/network-innbind.c
  branches/2.6/lib/network.c
  branches/2.6/lib/reallocarray.c
  branches/2.6/lib/setenv.c
  branches/2.6/lib/seteuid.c
  branches/2.6/lib/snprintf.c
  branches/2.6/lib/vector.c
  branches/2.6/lib/xmalloc.c
  branches/2.6/lib/xwrite.c
  branches/2.6/m4/cc-flags.m4
  branches/2.6/m4/krb5.m4
  branches/2.6/m4/snprintf.m4
  branches/2.6/m4/socket.m4
  branches/2.6/support/getrra-c-util
  branches/2.6/tests/lib/buffer-t.c
  branches/2.6/tests/lib/fakewrite.c
  branches/2.6/tests/lib/fdflag-t.c
  branches/2.6/tests/lib/getaddrinfo-t.c
  branches/2.6/tests/lib/getnameinfo-t.c
  branches/2.6/tests/lib/inet_aton-t.c
  branches/2.6/tests/lib/inet_ntoa-t.c
  branches/2.6/tests/lib/inet_ntop-t.c
  branches/2.6/tests/lib/messages-t.c
  branches/2.6/tests/lib/network/addr-ipv4-t.c
  branches/2.6/tests/lib/network/addr-ipv6-t.c
  branches/2.6/tests/lib/network/client-t.c
  branches/2.6/tests/lib/network/server-t.c
  branches/2.6/tests/lib/snprintf-t.c
  branches/2.6/tests/lib/xmalloc.c
  branches/2.6/tests/lib/xmalloc.t
  branches/2.6/tests/runtests.c
  branches/2.6/tests/tap/basic.c
  branches/2.6/tests/tap/basic.h
  branches/2.6/tests/tap/float.c
  branches/2.6/tests/tap/macros.h
  branches/2.6/tests/tap/process.c
  branches/2.6/tests/tap/process.h
  branches/2.6/tests/tap/string.h

---------------------------------+
 include/clibrary.h              |   42 +++++---
 include/inn/buffer.h            |   26 ++---
 include/inn/fdflag.h            |    2 
 include/inn/network-innbind.h   |    3 
 include/inn/network.h           |    6 -
 include/inn/vector.h            |    9 -
 include/inn/xmalloc.h           |   22 ++--
 include/portable/getaddrinfo.h  |   60 ++++++------
 include/portable/getnameinfo.h  |   38 ++++---
 include/portable/macros.h       |   24 ++--
 include/portable/socket-unix.h  |    4 
 include/portable/socket.h       |  128 +++++++++++++-------------
 include/portable/stdbool.h      |   34 +++---
 include/portable/uio.h          |    2 
 lib/asprintf.c                  |    8 -
 lib/buffer.c                    |    4 
 lib/fdflag.c                    |   18 +--
 lib/getaddrinfo.c               |   74 +++++++--------
 lib/getnameinfo.c               |   16 +--
 lib/inet_aton.c                 |   14 +-
 lib/inet_ntoa.c                 |   10 +-
 lib/inet_ntop.c                 |   14 +-
 lib/messages.c                  |   56 +++++------
 lib/mkstemp.c                   |    6 -
 lib/network-innbind.c           |    2 
 lib/network.c                   |   24 ++--
 lib/reallocarray.c              |    4 
 lib/setenv.c                    |    4 
 lib/seteuid.c                   |    2 
 lib/snprintf.c                  |   40 ++++++--
 lib/vector.c                    |   15 +--
 lib/xmalloc.c                   |    8 -
 lib/xwrite.c                    |   20 ++--
 m4/cc-flags.m4                  |    6 -
 m4/krb5.m4                      |    3 
 m4/snprintf.m4                  |    5 -
 m4/socket.m4                    |    2 
 support/getrra-c-util           |   16 ++-
 tests/lib/buffer-t.c            |   12 +-
 tests/lib/fakewrite.c           |    4 
 tests/lib/fdflag-t.c            |    2 
 tests/lib/getaddrinfo-t.c       |   27 ++---
 tests/lib/getnameinfo-t.c       |   16 +--
 tests/lib/inet_aton-t.c         |    8 +
 tests/lib/inet_ntoa-t.c         |    6 -
 tests/lib/inet_ntop-t.c         |    8 +
 tests/lib/messages-t.c          |   34 +++---
 tests/lib/network/addr-ipv4-t.c |    8 +
 tests/lib/network/addr-ipv6-t.c |    6 -
 tests/lib/network/client-t.c    |   32 +++---
 tests/lib/network/server-t.c    |  129 +++++++++++++++++++-------
 tests/lib/snprintf-t.c          |   48 ++++-----
 tests/lib/xmalloc.c             |   12 +-
 tests/lib/xmalloc.t             |   37 +++----
 tests/runtests.c                |  185 +++++++++++++++++++-------------------
 tests/tap/basic.c               |  170 +++++++++++++++++++---------------
 tests/tap/basic.h               |   35 +++----
 tests/tap/float.c               |   29 ++++-
 tests/tap/macros.h              |   32 +++---
 tests/tap/process.c             |   18 +--
 tests/tap/process.h             |    3 
 tests/tap/string.h              |    2 
 62 files changed, 894 insertions(+), 740 deletions(-)

Modified: include/clibrary.h
===================================================================
--- include/clibrary.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/clibrary.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -27,7 +27,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2014, 2016, 2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2014, 2016, 2018, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2006-2011, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -50,28 +50,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. */
@@ -79,12 +79,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
 
 /* Define sig_atomic_t if it's not available in signal.h. */
@@ -102,9 +102,9 @@
  * 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
 
 /*
@@ -123,13 +123,23 @@
  * 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
 
+/*
+ * If explicit_bzero is not available, fall back on memset.  This does NOT
+ * provide any of the security guarantees of explicit_bzero and will probably
+ * be optimized away by the compiler.  It just ensures that code will compile
+ * and function on systems without explicit_bzero.
+ */
+#if !HAVE_EXPLICIT_BZERO
+#    define explicit_bzero(s, n) memset((s), 0, (n))
+#endif
+
 BEGIN_DECLS
 
 /*

Modified: include/inn/buffer.h
===================================================================
--- include/inn/buffer.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/buffer.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -52,10 +52,10 @@
 #include <sys/types.h>
 
 struct buffer {
-    size_t size;                /* Total allocated length. */
-    size_t used;                /* Data already used. */
-    size_t left;                /* Remaining unused data. */
-    char *data;                 /* Pointer to allocated memory. */
+    size_t size; /* Total allocated length. */
+    size_t used; /* Data already used. */
+    size_t left; /* Remaining unused data. */
+    char *data;  /* Pointer to allocated memory. */
 };
 
 BEGIN_DECLS
@@ -71,15 +71,13 @@
  * Resize a buffer to be at least as large as the provided size.  Invalidates
  * pointers into the buffer.
  */
-void buffer_resize(struct buffer *, size_t)
-    __attribute__((__nonnull__));
+void buffer_resize(struct buffer *, size_t) __attribute__((__nonnull__));
 
 /*
  * Compact a buffer, removing all used data and moving unused data to the
  * beginning of the buffer.  Invalidates pointers into the buffer.
  */
-void buffer_compact(struct buffer *)
-    __attribute__((__nonnull__));
+void buffer_compact(struct buffer *) __attribute__((__nonnull__));
 
 /*
  * Set the buffer contents, ignoring anything currently there.  If length is
@@ -120,8 +118,7 @@
  * the fourth argument.  Returns false if the terminator isn't found.
  */
 bool buffer_find_string(struct buffer *, const char *, size_t start,
-                        size_t *offset)
-    __attribute__((__nonnull__));
+                        size_t *offset) __attribute__((__nonnull__));
 
 /*
  * Read from a file descriptor into a buffer, up to the available space in the
@@ -130,15 +127,13 @@
  * error or after any successful read.  Returns -1 on an error reading from
  * the file descriptor and sets errno.
  */
-ssize_t buffer_read(struct buffer *, int fd)
-    __attribute__((__nonnull__));
+ssize_t buffer_read(struct buffer *, int fd) __attribute__((__nonnull__));
 
 /*
  * Read from a file descriptor into a buffer until end of file is reached.
  * Returns true on success and false (setting errno) on error.
  */
-bool buffer_read_all(struct buffer *, int fd)
-    __attribute__((__nonnull__));
+bool buffer_read_all(struct buffer *, int fd) __attribute__((__nonnull__));
 
 /*
  * Read the contents of a file into a buffer.  This should be used instead of
@@ -145,8 +140,7 @@
  * buffer_read_all when fstat can be called on the file descriptor.  Returns
  * true on success and false (setting errno) on error.
  */
-bool buffer_read_file(struct buffer *, int fd)
-    __attribute__((__nonnull__));
+bool buffer_read_file(struct buffer *, int fd) __attribute__((__nonnull__));
 
 END_DECLS
 

Modified: include/inn/fdflag.h
===================================================================
--- include/inn/fdflag.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/fdflag.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -34,8 +34,8 @@
 
 #include <inn/defines.h>
 #include "inn/portable-macros.h"
+#include "inn/portable-socket.h"
 #include "inn/portable-stdbool.h"
-#include "inn/portable-socket.h"
 
 BEGIN_DECLS
 

Modified: include/inn/network-innbind.h
===================================================================
--- include/inn/network-innbind.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/network-innbind.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -39,8 +39,7 @@
  * count holding the count returned.
  */
 bool network_innbind_all(int type, unsigned short port, socket_type **fds,
-                         unsigned int *count)
-    __attribute__((__nonnull__));
+                         unsigned int *count) __attribute__((__nonnull__));
 
 END_DECLS
 

Modified: include/inn/network.h
===================================================================
--- include/inn/network.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/network.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -65,8 +65,7 @@
  * array of file descriptors when no longer needed.
  */
 bool network_bind_all(int type, unsigned short port, socket_type **fds,
-                      unsigned int *count)
-    __attribute__((__nonnull__));
+                      unsigned int *count) __attribute__((__nonnull__));
 void network_bind_all_free(socket_type *fds);
 
 /*
@@ -102,8 +101,7 @@
  * not use any particular source address.)
  */
 socket_type network_connect(const struct addrinfo *, const char *source,
-                            time_t)
-    __attribute__((__nonnull__(1)));
+                            time_t) __attribute__((__nonnull__(1)));
 
 /*
  * Like network_connect but takes a host and port instead.  If host lookup

Modified: include/inn/vector.h
===================================================================
--- include/inn/vector.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/vector.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -67,8 +67,7 @@
  * Resize the array of strings to hold size entries.  Saves reallocation work
  * in vector_add if it's known in advance how many entries there will be.
  */
-void vector_resize(struct vector *, size_t size)
-    __attribute__((__nonnull__));
+void vector_resize(struct vector *, size_t size) __attribute__((__nonnull__));
 void cvector_resize(struct cvector *, size_t size)
     __attribute__((__nonnull__));
 
@@ -77,10 +76,8 @@
  * regular vector, but not freeing the strings array (to cut down on memory
  * allocations if the vector will be reused).
  */
-void vector_clear(struct vector *)
-    __attribute__((__nonnull__));
-void cvector_clear(struct cvector *)
-    __attribute__((__nonnull__));
+void vector_clear(struct vector *) __attribute__((__nonnull__));
+void cvector_clear(struct cvector *) __attribute__((__nonnull__));
 
 /*
  * Free the vector and all resources allocated for it.  NULL may be passed in

Modified: include/inn/xmalloc.h
===================================================================
--- include/inn/xmalloc.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/inn/xmalloc.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -43,12 +43,12 @@
  * number information for debugging error messages without the user having to
  * pass those in every time.
  */
-#define xcalloc(n, size)        x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size)           x_malloc((size), __FILE__, __LINE__)
-#define xrealloc(p, size)       x_realloc((p), (size), __FILE__, __LINE__)
-#define xstrdup(p)              x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size)       x_strndup((p), (size), __FILE__, __LINE__)
-#define xvasprintf(p, f, a)     x_vasprintf((p), (f), (a), __FILE__, __LINE__)
+#define xcalloc(n, size)    x_calloc((n), (size), __FILE__, __LINE__)
+#define xmalloc(size)       x_malloc((size), __FILE__, __LINE__)
+#define xrealloc(p, size)   x_realloc((p), (size), __FILE__, __LINE__)
+#define xstrdup(p)          x_strdup((p), __FILE__, __LINE__)
+#define xstrndup(p, size)   x_strndup((p), (size), __FILE__, __LINE__)
+#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__)
 #define xreallocarray(p, n, size) \
     x_reallocarray((p), (n), (size), __FILE__, __LINE__)
 
@@ -61,13 +61,13 @@
  * are supported.
  */
 #ifdef INN_HAVE_C99_VAMACROS
-# define xasprintf(p, f, ...) \
-    x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__)
+#    define xasprintf(p, f, ...) \
+        x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__)
 #elif INN_HAVE_GNU_VAMACROS
-# define xasprintf(p, f, args...) \
-    x_asprintf((p), __FILE__, __LINE__, (f), args)
+#    define xasprintf(p, f, args...) \
+        x_asprintf((p), __FILE__, __LINE__, (f), args)
 #else
-# define xasprintf x_asprintf
+#    define xasprintf x_asprintf
 #endif
 
 BEGIN_DECLS

Modified: include/portable/getaddrinfo.h
===================================================================
--- include/portable/getaddrinfo.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/getaddrinfo.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -4,7 +4,7 @@
  *
  * This is an implementation of the getaddrinfo family of functions for
  * systems that lack it, so that code can use getaddrinfo always.  It provides
- * IPv4 support only; for IPv6 support, a native getaddrinfo implemenation is
+ * IPv4 support only; for IPv6 support, a native getaddrinfo implementation is
  * required.
  *
  * This file should generally be included by way of portable/socket.h rather
@@ -14,7 +14,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2003, 2005 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2003, 2005, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008-2011
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -36,41 +36,43 @@
 #ifndef HAVE_GETADDRINFO
 
 /* OpenBSD likes to have sys/types.h included before sys/socket.h. */
-#include <sys/types.h>
-#include <sys/socket.h>
+/* clang-format off */
+#    include <sys/types.h>
+#    include <sys/socket.h>
+/* clang-format on */
 
 /* The struct returned by getaddrinfo, from RFC 3493. */
 struct addrinfo {
-    int ai_flags;               /* AI_PASSIVE, AI_CANONNAME, .. */
-    int ai_family;              /* AF_xxx */
-    int ai_socktype;            /* SOCK_xxx */
-    int ai_protocol;            /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
-    socklen_t ai_addrlen;       /* Length of ai_addr */
-    char *ai_canonname;         /* Canonical name for nodename */
-    struct sockaddr *ai_addr;   /* Binary address */
-    struct addrinfo *ai_next;   /* Next structure in linked list */
+    int ai_flags;             /* AI_PASSIVE, AI_CANONNAME, .. */
+    int ai_family;            /* AF_xxx */
+    int ai_socktype;          /* SOCK_xxx */
+    int ai_protocol;          /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
+    socklen_t ai_addrlen;     /* Length of ai_addr */
+    char *ai_canonname;       /* Canonical name for nodename */
+    struct sockaddr *ai_addr; /* Binary address */
+    struct addrinfo *ai_next; /* Next structure in linked list */
 };
 
 /* Constants for ai_flags from RFC 3493, combined with binary or. */
-#define AI_PASSIVE      0x0001
-#define AI_CANONNAME    0x0002
-#define AI_NUMERICHOST  0x0004
-#define AI_NUMERICSERV  0x0008
-#define AI_V4MAPPED     0x0010
-#define AI_ALL          0x0020
-#define AI_ADDRCONFIG   0x0040
+#    define AI_PASSIVE     0x0001
+#    define AI_CANONNAME   0x0002
+#    define AI_NUMERICHOST 0x0004
+#    define AI_NUMERICSERV 0x0008
+#    define AI_V4MAPPED    0x0010
+#    define AI_ALL         0x0020
+#    define AI_ADDRCONFIG  0x0040
 
 /* Error return codes from RFC 3493. */
-#define EAI_AGAIN       1       /* Temporary name resolution failure */
-#define EAI_BADFLAGS    2       /* Invalid value in ai_flags parameter */
-#define EAI_FAIL        3       /* Permanent name resolution failure */
-#define EAI_FAMILY      4       /* Address family not recognized */
-#define EAI_MEMORY      5       /* Memory allocation failure */
-#define EAI_NONAME      6       /* nodename or servname unknown */
-#define EAI_SERVICE     7       /* Service not recognized for socket type */
-#define EAI_SOCKTYPE    8       /* Socket type not recognized */
-#define EAI_SYSTEM      9       /* System error occurred, see errno */
-#define EAI_OVERFLOW    10      /* An argument buffer overflowed */
+#    define EAI_AGAIN    1  /* Temporary name resolution failure */
+#    define EAI_BADFLAGS 2  /* Invalid value in ai_flags parameter */
+#    define EAI_FAIL     3  /* Permanent name resolution failure */
+#    define EAI_FAMILY   4  /* Address family not recognized */
+#    define EAI_MEMORY   5  /* Memory allocation failure */
+#    define EAI_NONAME   6  /* nodename or servname unknown */
+#    define EAI_SERVICE  7  /* Service not recognized for socket type */
+#    define EAI_SOCKTYPE 8  /* Socket type not recognized */
+#    define EAI_SYSTEM   9  /* System error occurred, see errno */
+#    define EAI_OVERFLOW 10 /* An argument buffer overflowed */
 
 BEGIN_DECLS
 

Modified: include/portable/getnameinfo.h
===================================================================
--- include/portable/getnameinfo.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/getnameinfo.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -4,7 +4,7 @@
  *
  * This is an implementation of the getnameinfo function for systems that lack
  * it, so that code can use getnameinfo always.  It provides IPv4 support
- * only; for IPv6 support, a native getnameinfo implemenation is required.
+ * only; for IPv6 support, a native getnameinfo implementation is required.
  *
  * This file should generally be included by way of portable/socket.h rather
  * than directly.
@@ -13,7 +13,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2007 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2007, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2010-2011
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -35,15 +35,17 @@
 #if !HAVE_GETNAMEINFO
 
 /* OpenBSD likes to have sys/types.h included before sys/socket.h. */
-#include <sys/types.h>
-#include <sys/socket.h>
+/* clang-format off */
+#    include <sys/types.h>
+#    include <sys/socket.h>
+/* clang-format on */
 
 /* Constants for flags from RFC 3493, combined with binary or. */
-#define NI_NOFQDN       0x0001
-#define NI_NUMERICHOST  0x0002
-#define NI_NAMEREQD     0x0004
-#define NI_NUMERICSERV  0x0008
-#define NI_DGRAM        0x0010
+#    define NI_NOFQDN      0x0001
+#    define NI_NUMERICHOST 0x0002
+#    define NI_NAMEREQD    0x0004
+#    define NI_NUMERICSERV 0x0008
+#    define NI_DGRAM       0x0010
 
 /*
  * Maximum length of hostnames and service names.  Our implementation doesn't
@@ -50,19 +52,19 @@
  * use these values, so they're taken from Linux.  They're provided just for
  * code that uses them to size buffers.
  */
-#ifndef NI_MAXHOST
-# define NI_MAXHOST     1025
-#endif
-#ifndef NI_MAXSERV
-# define NI_MAXSERV     32
-#endif
+#    ifndef NI_MAXHOST
+#        define NI_MAXHOST 1025
+#    endif
+#    ifndef NI_MAXSERV
+#        define NI_MAXSERV 32
+#    endif
 
 BEGIN_DECLS
 
 /* Function prototypes. */
-int getnameinfo(const struct sockaddr *sa, socklen_t salen,
-                char *node, socklen_t nodelen,
-                char *service, socklen_t servicelen, int flags);
+int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node,
+                socklen_t nodelen, char *service, socklen_t servicelen,
+                int flags);
 
 END_DECLS
 

Modified: include/portable/macros.h
===================================================================
--- include/portable/macros.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/macros.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -27,9 +27,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
 
 /*
@@ -40,10 +40,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
 
 /*
@@ -53,7 +53,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
 
 /*
@@ -63,11 +63,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 */

Modified: include/portable/socket-unix.h
===================================================================
--- include/portable/socket-unix.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/socket-unix.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -33,8 +33,8 @@
  * (2nd edition), vol. 1, pg. 917.
  */
 #if !HAVE_SUN_LEN
-# define SUN_LEN(sun) \
-    (sizeof(*(sun)) - sizeof((sun)->sun_path) + strlen((sun)->sun_path))
+#    define SUN_LEN(sun) \
+        (sizeof(*(sun)) - sizeof((sun)->sun_path) + strlen((sun)->sun_path))
 #endif
 
 #endif /* !PORTABLE_SOCKET_UNIX_H */

Modified: include/portable/socket.h
===================================================================
--- include/portable/socket.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/socket.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -17,7 +17,7 @@
  * The canonical version of this file is maintained in the rra-c-util package,
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
- * Copyright 2014, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2014, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008-2009, 2011, 2013
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright 2004-2007 Internet Systems Consortium, Inc. ("ISC")
@@ -51,15 +51,17 @@
 #include <sys/types.h>
 
 /* BSDI needs <netinet/in.h> before <arpa/inet.h>. */
+/* clang-format off */
 #ifdef _WIN32
-# include <winsock2.h>
-# include <ws2tcpip.h>
+#    include <winsock2.h>
+#    include <ws2tcpip.h>
 #else
-# include <netinet/in.h>
-# include <arpa/inet.h>
-# include <netdb.h>
-# include <sys/socket.h>
+#    include <netinet/in.h>
+#    include <arpa/inet.h>
+#    include <netdb.h>
+#    include <sys/socket.h>
 #endif
+/* clang-format on */
 
 /*
  * Pick up definitions of getaddrinfo and getnameinfo if not otherwise
@@ -79,18 +81,19 @@
  * platforms that may require 64-bit alignment for the embedded addresses.
  */
 #if !HAVE_STRUCT_SOCKADDR_STORAGE
-# define SS_MAXSIZE_ 128
-# ifdef HAVE_LONG_LONG_INT
-#  define SS_ALIGNSIZE_ sizeof(long long)
-#  define SS_ALIGNTYPE_ long long
-# else
-#  define SS_ALIGNSIZE_ sizeof(long)
-#  define SS_ALIGNTYPE_ long
-# endif
-# if HAVE_STRUCT_SOCKADDR_SA_LEN
-#  define SS_PAD1SIZE_ (SS_ALIGNSIZE_ - 2 * sizeof(unsigned char))
-#  define SS_PAD2SIZE_ \
-    (SS_MAXSIZE_ - (2 * sizeof(unsigned char) + SS_PAD1SIZE_ + SS_ALIGNSIZE_))
+#    define SS_MAXSIZE_ 128
+#    ifdef HAVE_LONG_LONG_INT
+#        define SS_ALIGNSIZE_ sizeof(long long)
+#        define SS_ALIGNTYPE_ long long
+#    else
+#        define SS_ALIGNSIZE_ sizeof(long)
+#        define SS_ALIGNTYPE_ long
+#    endif
+#    if HAVE_STRUCT_SOCKADDR_SA_LEN
+#        define SS_PAD1SIZE_ (SS_ALIGNSIZE_ - 2 * sizeof(unsigned char))
+#        define SS_PAD2SIZE_ \
+            (SS_MAXSIZE_     \
+             - (2 * sizeof(unsigned char) + SS_PAD1SIZE_ + SS_ALIGNSIZE_))
 struct sockaddr_storage {
     unsigned char ss_len;
     unsigned char ss_family;
@@ -98,10 +101,11 @@
     SS_ALIGNTYPE_ __ss_align;
     char __ss_pad2[SS_PAD2SIZE_];
 };
-# else
-#  define SS_PAD1SIZE_ (SS_ALIGNSIZE_ - sizeof(unsigned char))
-#  define SS_PAD2SIZE_ \
-    (SS_MAXSIZE_ - (sizeof(unsigned char) + SS_PAD1SIZE_ + SS_ALIGNSIZE_))
+#    else
+#        define SS_PAD1SIZE_ (SS_ALIGNSIZE_ - sizeof(unsigned char))
+#        define SS_PAD2SIZE_ \
+            (SS_MAXSIZE_     \
+             - (sizeof(unsigned char) + SS_PAD1SIZE_ + SS_ALIGNSIZE_))
 struct sockaddr_storage {
     unsigned short ss_family;
     char __ss_pad1[SS_PAD1SIZE_];
@@ -108,7 +112,7 @@
     SS_ALIGNTYPE_ __ss_align;
     char __ss_pad2[SS_PAD2SIZE_];
 };
-# endif
+#    endif
 #endif
 
 /*
@@ -116,15 +120,15 @@
  * instead of the non-uglified names from RFC 3493.
  */
 #if HAVE_STRUCT_SOCKADDR_STORAGE && !HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
-# define ss_family __ss_family
-# define ss_len    __ss_len
+#    define ss_family __ss_family
+#    define ss_len    __ss_len
 #endif
 
 /* Fix IN6_ARE_ADDR_EQUAL if required. */
 #ifdef HAVE_BROKEN_IN6_ARE_ADDR_EQUAL
-# undef IN6_ARE_ADDR_EQUAL
-# define IN6_ARE_ADDR_EQUAL(a, b) \
-    (memcmp((a), (b), sizeof(struct in6_addr)) == 0)
+#    undef IN6_ARE_ADDR_EQUAL
+#    define IN6_ARE_ADDR_EQUAL(a, b) \
+        (memcmp((a), (b), sizeof(struct in6_addr)) == 0)
 #endif
 
 /*
@@ -133,7 +137,7 @@
  * doesn't exist.
  */
 #if !defined(HAVE_GETADDRINFO_ADDRCONFIG) && defined(AI_ADDRCONFIG)
-# undef AI_ADDRCONFIG
+#    undef AI_ADDRCONFIG
 #endif
 
 /*
@@ -143,10 +147,10 @@
  * them harmlessly go away.
  */
 #ifndef AI_ADDRCONFIG
-# define AI_ADDRCONFIG 0
+#    define AI_ADDRCONFIG 0
 #endif
 #ifndef AI_NUMERICSERV
-# define AI_NUMERICSERV 0
+#    define AI_NUMERICSERV 0
 #endif
 
 /*
@@ -154,10 +158,10 @@
  * nul-terminated text representation of the given address type.
  */
 #ifndef INET_ADDRSTRLEN
-# define INET_ADDRSTRLEN 16
+#    define INET_ADDRSTRLEN 16
 #endif
 #ifndef INET6_ADDRSTRLEN
-# define INET6_ADDRSTRLEN 46
+#    define INET6_ADDRSTRLEN 46
 #endif
 
 /*
@@ -165,7 +169,7 @@
  * available on systems too old to have that function.
  */
 #ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EDOM
+#    define EAFNOSUPPORT EDOM
 #endif
 
 /*
@@ -175,7 +179,7 @@
  * unconditionally.
  */
 #ifndef EAI_ADDRFAMILY
-# define EAI_ADDRFAMILY EAI_FAMILY
+#    define EAI_ADDRFAMILY EAI_FAMILY
 #endif
 
 BEGIN_DECLS
@@ -187,28 +191,28 @@
  * accordingly.
  */
 #if !HAVE_DECL_INET_ATON
-# if !HAVE_INET_ATON
+#    if !HAVE_INET_ATON
 extern int inet_aton(const char *, struct in_addr *)
     __attribute__((__visibility__("hidden")));
-# else
+#    else
 extern int inet_aton(const char *, struct in_addr *);
-# endif
+#    endif
 #endif
 #if !HAVE_DECL_INET_NTOA
-# if !HAVE_INET_NTOA
+#    if !HAVE_INET_NTOA
 extern char *inet_ntoa(struct in_addr)
     __attribute__((__visibility__("hidden")));
-# else
+#    else
 extern char *inet_ntoa(struct in_addr);
-# endif
+#    endif
 #endif
 
 #if !HAVE_INET_NTOP
-# ifdef _WIN32
+#    ifdef _WIN32
 extern const char *inet_ntop(int, const void *, char *, int);
-# else
+#    else
 extern const char *inet_ntop(int, const void *, char *, socklen_t);
-# endif
+#    endif
 #endif
 
 /*
@@ -240,26 +244,26 @@
  */
 #ifdef _WIN32
 int socket_init(void);
-# define socket_shutdown()              WSACleanup()
-# define socket_close(fd)               closesocket(fd)
-# define socket_read(fd, b, s)          recv((fd), (b), (s), 0)
-# define socket_write(fd, b, s)         send((fd), (b), (s), 0)
-# define socket_errno                   WSAGetLastError()
-# define socket_set_errno(e)            WSASetLastError(e)
-# define socket_set_errno_einval()      WSASetLastError(WSAEINVAL)
+#    define socket_shutdown()         WSACleanup()
+#    define socket_close(fd)          closesocket(fd)
+#    define socket_read(fd, b, s)     recv((fd), (b), (s), 0)
+#    define socket_write(fd, b, s)    send((fd), (b), (s), 0)
+#    define socket_errno              WSAGetLastError()
+#    define socket_set_errno(e)       WSASetLastError(e)
+#    define socket_set_errno_einval() WSASetLastError(WSAEINVAL)
 const char *socket_strerror(int);
 typedef SOCKET socket_type;
 #else
-# define socket_init()                  1
-# define socket_shutdown()              /* empty */
-# define socket_close(fd)               close(fd)
-# define socket_read(fd, b, s)          read((fd), (b), (s))
-# define socket_write(fd, b, s)         write((fd), (b), (s))
-# define socket_errno                   errno
-# define socket_set_errno(e)            errno = (e)
-# define socket_set_errno_einval()      errno = EINVAL
-# define socket_strerror(e)             strerror(e)
-# define INVALID_SOCKET                 -1
+#    define socket_init()             1
+#    define socket_shutdown()         /* empty */
+#    define socket_close(fd)          close(fd)
+#    define socket_read(fd, b, s)     read((fd), (b), (s))
+#    define socket_write(fd, b, s)    write((fd), (b), (s))
+#    define socket_errno              errno
+#    define socket_set_errno(e)       errno = (e)
+#    define socket_set_errno_einval() errno = EINVAL
+#    define socket_strerror(e)        strerror(e)
+#    define INVALID_SOCKET            -1
 typedef int socket_type;
 #endif
 

Modified: include/portable/stdbool.h
===================================================================
--- include/portable/stdbool.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/stdbool.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -29,28 +29,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
 
 /*
@@ -58,7 +58,7 @@
  * 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 */

Modified: include/portable/uio.h
===================================================================
--- include/portable/uio.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ include/portable/uio.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -28,7 +28,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;

Modified: lib/asprintf.c
===================================================================
--- lib/asprintf.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/asprintf.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -32,10 +32,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)

Modified: lib/buffer.c
===================================================================
--- lib/buffer.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/buffer.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -17,7 +17,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2015-2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2015-2016, 2019 Russ Allbery <eagle at eyrie.org>
  * Copyright 2011-2012, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC")
@@ -44,6 +44,7 @@
 #include "config.h"
 #include "clibrary.h"
 
+#include <assert.h>
 #include <errno.h>
 #include <sys/stat.h>
 
@@ -112,6 +113,7 @@
 buffer_set(struct buffer *buffer, const char *data, size_t length)
 {
     if (length > 0) {
+        assert(data != NULL);
         buffer_resize(buffer, length);
         memmove(buffer->data, data, length);
     }

Modified: lib/fdflag.c
===================================================================
--- lib/fdflag.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/fdflag.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -36,15 +36,15 @@
 #include "clibrary.h"
 
 #ifdef _WIN32
-# include <winsock2.h>
+#    include <winsock2.h>
 #else
-# include <fcntl.h>
-# ifndef O_NONBLOCK
-#  include <sys/ioctl.h>
-#  if HAVE_SYS_FILIO_H
-#   include <sys/filio.h>
-#  endif
-# endif
+#    include <fcntl.h>
+#    ifndef O_NONBLOCK
+#        include <sys/ioctl.h>
+#        if HAVE_SYS_FILIO_H
+#            include <sys/filio.h>
+#        endif
+#    endif
 #endif
 
 #include "inn/fdflag.h"
@@ -142,7 +142,7 @@
     mode = (flag ? (mode | O_NONBLOCK) : (mode & ~O_NONBLOCK));
     return (fcntl(fd, F_SETFL, mode) == 0);
 }
-#else /* !O_NONBLOCK */
+#else  /* !O_NONBLOCK */
 bool
 fdflag_nonblocking(socket_type fd, bool flag)
 {

Modified: lib/getaddrinfo.c
===================================================================
--- lib/getaddrinfo.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/getaddrinfo.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -3,7 +3,7 @@
  * Replacement for a missing getaddrinfo.
  *
  * This is an implementation of getaddrinfo for systems that don't have one so
- * that networking code can use a consistant interface without #ifdef.  It is
+ * that networking code can use a consistent interface without #ifdef.  It is
  * a fairly minimal implementation, with the following limitations:
  *
  *   - IPv4 support only.  IPv6 is not supported.
@@ -21,7 +21,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2003-2005, 2016-2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2003-2005, 2016-2017, 2019-2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2015 Julien ÉLIE <julien at trigofacile.com>
  * Copyright 2008, 2011, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
@@ -35,8 +35,8 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 
@@ -51,13 +51,13 @@
  * defined so that we can deal with them in case statements.
  */
 #ifndef HOST_NOT_FOUND
-# define HOST_NOT_FOUND 1
-# define TRY_AGAIN      2
-# define NO_RECOVERY    3
-# define NO_DATA        4
+#    define HOST_NOT_FOUND 1
+#    define TRY_AGAIN      2
+#    define NO_RECOVERY    3
+#    define NO_DATA        4
 #endif
 #ifndef NETDB_INTERNAL
-# define NETDB_INTERNAL -1
+#    define NETDB_INTERNAL -1
 #endif
 
 /*
@@ -66,12 +66,12 @@
  * constants, but that should be okay (except possibly for gai_strerror).
  */
 #if TESTING
-# undef gai_strerror
-# undef freeaddrinfo
-# undef getaddrinfo
-# define gai_strerror test_gai_strerror
-# define freeaddrinfo test_freeaddrinfo
-# define getaddrinfo  test_getaddrinfo
+#    undef gai_strerror
+#    undef freeaddrinfo
+#    undef getaddrinfo
+#    define gai_strerror test_gai_strerror
+#    define freeaddrinfo test_freeaddrinfo
+#    define getaddrinfo  test_getaddrinfo
 const char *test_gai_strerror(int);
 void test_freeaddrinfo(struct addrinfo *);
 int test_getaddrinfo(const char *, const char *, const struct addrinfo *,
@@ -83,14 +83,14 @@
  * pick some other values for them.
  */
 #if TESTING
-# if AI_NUMERICSERV == 0
-#  undef AI_NUMERICSERV
-#  define AI_NUMERICSERV 0x0080
-# endif
-# if AI_NUMERICHOST == 0
-#  undef AI_NUMERICHOST
-#  define AI_NUMERICHOST 0x0100
-# endif
+#    if AI_NUMERICSERV == 0
+#        undef AI_NUMERICSERV
+#        define AI_NUMERICSERV 0x0080
+#    endif
+#    if AI_NUMERICHOST == 0
+#        undef AI_NUMERICHOST
+#        define AI_NUMERICHOST 0x0100
+#    endif
 #endif
 
 /*
@@ -99,17 +99,17 @@
  * on these platforms.
  */
 #if TESTING
-# ifdef HAVE_GETADDRINFO
-#  define AI_INTERNAL_ALL 0x1fff
-# else
-#  define AI_INTERNAL_ALL 0x01ff
-# endif
+#    ifdef HAVE_GETADDRINFO
+#        define AI_INTERNAL_ALL 0x1fff
+#    else
+#        define AI_INTERNAL_ALL 0x01ff
+#    endif
 #else
-# define AI_INTERNAL_ALL 0x007f
+#    define AI_INTERNAL_ALL 0x007f
 #endif
 
 /* Table of strings corresponding to the EAI_* error codes. */
-static const char * const gai_errors[] = {
+static const char *const gai_errors[] = {
     "Host name lookup failure",         /*  1 EAI_AGAIN */
     "Invalid flag value",               /*  2 EAI_BADFLAGS */
     "Unknown server error",             /*  3 EAI_FAIL */
@@ -124,9 +124,9 @@
 
 /* Macro to set the len attribute of sockaddr_in. */
 #if HAVE_STRUCT_SOCKADDR_SA_LEN
-# define sin_set_length(s) ((s)->sin_len  = sizeof(struct sockaddr_in))
+#    define sin_set_length(s) ((s)->sin_len = sizeof(struct sockaddr_in))
 #else
-# define sin_set_length(s) /* empty */
+#    define sin_set_length(s) /* empty */
 #endif
 
 /*
@@ -213,7 +213,6 @@
         free(ai);
         return NULL;
     }
-    ai->ai_addr = (struct sockaddr *) sin;
     ai->ai_next = NULL;
     if (canonical == NULL)
         ai->ai_canonname = NULL;
@@ -220,8 +219,8 @@
     else {
         ai->ai_canonname = strdup(canonical);
         if (ai->ai_canonname == NULL) {
-            /* sin will be freed by freeaddrinfo. */
-            freeaddrinfo(ai);
+            free(sin);
+            free(ai);
             return NULL;
         }
     }
@@ -229,11 +228,12 @@
     ai->ai_family = AF_INET;
     ai->ai_socktype = socktype;
     ai->ai_protocol = (socktype == SOCK_DGRAM) ? IPPROTO_UDP : IPPROTO_TCP;
-    ai->ai_addrlen = sizeof(struct sockaddr_in);
     sin->sin_family = AF_INET;
     sin->sin_addr = addr;
     sin->sin_port = htons(port);
     sin_set_length(sin);
+    ai->ai_addr = (struct sockaddr *) sin;
+    ai->ai_addrlen = sizeof(struct sockaddr_in);
     return ai;
 }
 
@@ -332,8 +332,8 @@
         if (host->h_addr_list[0] == NULL)
             return EAI_FAIL;
         canonical = (flags & AI_CANONNAME)
-            ? ((host->h_name != NULL) ? host->h_name : nodename)
-            : NULL;
+                        ? ((host->h_name != NULL) ? host->h_name : nodename)
+                        : NULL;
         first = NULL;
         prev = NULL;
         for (i = 0; host->h_addr_list[i] != NULL; i++) {

Modified: lib/getnameinfo.c
===================================================================
--- lib/getnameinfo.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/getnameinfo.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -3,7 +3,7 @@
  * Replacement for a missing getnameinfo.
  *
  * This is an implementation of getnameinfo for systems that don't have one so
- * that networking code can use a consistant interface without #ifdef.  It is
+ * that networking code can use a consistent interface without #ifdef.  It is
  * a fairly minimal implementation, with the following limitations:
  *
  *   - IPv4 support only.  IPv6 is not supported.
@@ -18,7 +18,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2011, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -43,19 +43,19 @@
  * constants, but that should be okay (except possibly for gai_strerror).
  */
 #if TESTING
-# undef getnameinfo
-# define getnameinfo test_getnameinfo
+#    undef getnameinfo
+#    define getnameinfo test_getnameinfo
 int test_getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t,
                      char *, socklen_t, int);
 
 /* Linux doesn't provide EAI_OVERFLOW, so make up our own for testing. */
-# ifndef EAI_OVERFLOW
-#  define EAI_OVERFLOW 10
-# endif
+#    ifndef EAI_OVERFLOW
+#        define EAI_OVERFLOW 10
+#    endif
 #endif
 
 /* Used for unused parameters to silence gcc warnings. */
-#define UNUSED  __attribute__((__unused__))
+#define UNUSED __attribute__((__unused__))
 
 
 /*

Modified: lib/inet_aton.c
===================================================================
--- lib/inet_aton.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/inet_aton.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -10,7 +10,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2000-2001, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2017, 2019-2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2011, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -23,8 +23,8 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 /*
  * If we're running the test suite, rename inet_aton to avoid conflicts with
@@ -31,8 +31,8 @@
  * the system version.
  */
 #if TESTING
-# undef inet_aton
-# define inet_aton test_inet_aton
+#    undef inet_aton
+#    define inet_aton test_inet_aton
 int test_inet_aton(const char *, struct in_addr *);
 #endif
 
@@ -42,8 +42,8 @@
     unsigned octet[4];
     uint32_t address;
     const char *p;
-    int base, i;
-    int part = 0;
+    unsigned int base, i;
+    unsigned int part = 0;
 
     if (s == NULL)
         return 0;
@@ -98,6 +98,7 @@
              * Use a switch statement to parse each digit rather than assuming
              * ASCII.  Probably pointless portability.
              */
+            /* clang-format off */
             switch (*p) {
             case '0':           i = 0;  break;
             case '1':           i = 1;  break;
@@ -117,6 +118,7 @@
             case 'F': case 'f': i = 15; break;
             default:            return 0;
             }
+            /* clang-format on */
             if (i >= base)
                 return 0;
             octet[part] = (octet[part] * base) + i;

Modified: lib/inet_ntoa.c
===================================================================
--- lib/inet_ntoa.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/inet_ntoa.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -11,7 +11,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2000-2001, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2011, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -24,8 +24,8 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 /*
  * If we're running the test suite, rename inet_ntoa to avoid conflicts with
@@ -32,8 +32,8 @@
  * the system version.
  */
 #if TESTING
-# undef inet_ntoa
-# define inet_ntoa test_inet_ntoa
+#    undef inet_ntoa
+#    define inet_ntoa test_inet_ntoa
 char *test_inet_ntoa(struct in_addr);
 #endif
 
@@ -44,8 +44,10 @@
     const unsigned char *p;
 
     p = (const unsigned char *) &in.s_addr;
+    /* clang-format off */
     sprintf(buf, "%u.%u.%u.%u",
             (unsigned int) (p[0] & 0xff), (unsigned int) (p[1] & 0xff),
             (unsigned int) (p[2] & 0xff), (unsigned int) (p[3] & 0xff));
+    /* clang-format on */
     return buf;
 }

Modified: lib/inet_ntop.c
===================================================================
--- lib/inet_ntop.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/inet_ntop.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -12,7 +12,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2011, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -25,19 +25,19 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 
 /* This may already be defined by the system headers. */
 #ifndef INET_ADDRSTRLEN
-# define INET_ADDRSTRLEN 16
+#    define INET_ADDRSTRLEN 16
 #endif
 
 /* Systems old enough to not support inet_ntop may not have this either. */
 #ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EDOM
+#    define EAFNOSUPPORT EDOM
 #endif
 
 /*
@@ -45,8 +45,8 @@
  * the system version.
  */
 #if TESTING
-# undef inet_ntop
-# define inet_ntop test_inet_ntop
+#    undef inet_ntop
+#    define inet_ntop test_inet_ntop
 const char *test_inet_ntop(int, const void *, char *, socklen_t);
 #endif
 
@@ -65,11 +65,13 @@
         return NULL;
     }
     p = src;
+    /* clang-format off */
     status = snprintf(dst, size, "%u.%u.%u.%u",
                       (unsigned int) (p[0] & 0xff),
                       (unsigned int) (p[1] & 0xff),
                       (unsigned int) (p[2] & 0xff),
                       (unsigned int) (p[3] & 0xff));
+    /* clang-format on */
     if (status < 0 || (size_t) status >= (size_t) size)
         return NULL;
     return dst;

Modified: lib/messages.c
===================================================================
--- lib/messages.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/messages.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -55,7 +55,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2015-2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2015-2016, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008-2010, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC")
@@ -84,17 +84,17 @@
 
 #include <errno.h>
 #ifdef HAVE_SYSLOG_H
-# include <syslog.h>
+#    include <syslog.h>
 #endif
 
 #ifdef _WIN32
-# include <windows.h>
-# define LOG_DEBUG      EVENTLOG_SUCCESS
-# define LOG_INFO       EVENTLOG_INFORMATION_TYPE
-# define LOG_NOTICE     EVENTLOG_INFORMATION_TYPE
-# define LOG_WARNING    EVENTLOG_WARNING_TYPE
-# define LOG_ERR        EVENTLOG_ERROR_TYPE
-# define LOG_CRIT       EVENTLOG_ERROR_TYPE
+#    include <windows.h>
+#    define LOG_DEBUG   EVENTLOG_SUCCESS
+#    define LOG_INFO    EVENTLOG_INFORMATION_TYPE
+#    define LOG_NOTICE  EVENTLOG_INFORMATION_TYPE
+#    define LOG_WARNING EVENTLOG_WARNING_TYPE
+#    define LOG_ERR     EVENTLOG_ERROR_TYPE
+#    define LOG_CRIT    EVENTLOG_ERROR_TYPE
 #endif
 
 #include "inn/macros.h"
@@ -102,18 +102,14 @@
 #include "inn/xmalloc.h"
 
 /* The default handler lists. */
-static message_handler_func stdout_handlers[2] = {
-    message_log_stdout, NULL
-};
-static message_handler_func stderr_handlers[2] = {
-    message_log_stderr, NULL
-};
+static message_handler_func stdout_handlers[2] = {message_log_stdout, NULL};
+static message_handler_func stderr_handlers[2] = {message_log_stderr, NULL};
 
 /* The list of logging functions currently in effect. */
-static message_handler_func *debug_handlers  = NULL;
+static message_handler_func *debug_handlers = NULL;
 static message_handler_func *notice_handlers = stdout_handlers;
-static message_handler_func *warn_handlers   = stderr_handlers;
-static message_handler_func *die_handlers    = stderr_handlers;
+static message_handler_func *warn_handlers = stderr_handlers;
+static message_handler_func *die_handlers = stderr_handlers;
 
 /* If non-NULL, called before exit and its return value passed to exit. */
 int (*message_fatal_cleanup)(void) = NULL;
@@ -145,16 +141,18 @@
  * duplication since we can't assume variadic macros, but I can at least make
  * it easier to write and keep them consistent.
  */
-#define HANDLER_FUNCTION(type)                                  \
-    void                                                        \
-    message_handlers_ ## type(unsigned int count, ...)          \
-    {                                                           \
-        va_list args;                                           \
-                                                                \
-        va_start(args, count);                                  \
-        message_handlers(& type ## _handlers, count, args);     \
-        va_end(args);                                           \
+/* clang-format off */
+#define HANDLER_FUNCTION(type)                              \
+    void                                                    \
+    message_handlers_ ## type(unsigned int count, ...)      \
+    {                                                       \
+        va_list args;                                       \
+                                                            \
+        va_start(args, count);                              \
+        message_handlers(& type ## _handlers, count, args); \
+        va_end(args);                                       \
     }
+/* clang-format on */
 HANDLER_FUNCTION(debug)
 HANDLER_FUNCTION(notice)
 HANDLER_FUNCTION(warn)
@@ -255,7 +253,7 @@
             CloseEventLog(eventlog);
         }
     }
-#else /* !_WIN32 */
+#else  /* !_WIN32 */
     if (err == 0)
         syslog(pri, "%s", buffer);
     else
@@ -269,6 +267,7 @@
  * Do the same sort of wrapper to generate all of the separate syslog logging
  * functions.
  */
+/* clang-format off */
 #define SYSLOG_FUNCTION(name, type)                                        \
     void                                                                   \
     message_log_syslog_ ## name(size_t l, const char *f, va_list a, int e) \
@@ -281,6 +280,7 @@
 SYSLOG_FUNCTION(warning, WARNING)
 SYSLOG_FUNCTION(err,     ERR)
 SYSLOG_FUNCTION(crit,    CRIT)
+/* clang-format on */
 
 
 /*

Modified: lib/mkstemp.c
===================================================================
--- lib/mkstemp.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/mkstemp.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -26,7 +26,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+#    include <sys/time.h>
 #endif
 #include <time.h>
 
@@ -36,8 +36,8 @@
  * another name.
  */
 #if TESTING
-# undef mkstemp
-# define mkstemp test_mkstemp
+#    undef mkstemp
+#    define mkstemp test_mkstemp
 int test_mkstemp(char *);
 #endif
 

Modified: lib/network-innbind.c
===================================================================
--- lib/network-innbind.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/network-innbind.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -15,8 +15,8 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 #ifdef HAVE_STREAMS_SENDFD

Modified: lib/network.c
===================================================================
--- lib/network.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/network.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -46,15 +46,15 @@
  */
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 #ifdef HAVE_SYS_SELECT_H
-# include <sys/select.h>
+#    include <sys/select.h>
 #endif
 #ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+#    include <sys/time.h>
 #endif
 #include <time.h>
 
@@ -68,11 +68,11 @@
 
 /* Macros to set the len attribute of sockaddrs. */
 #if HAVE_STRUCT_SOCKADDR_SA_LEN
-# define sin_set_length(s)      ((s)->sin_len  = sizeof(struct sockaddr_in))
-# define sin6_set_length(s)     ((s)->sin6_len = sizeof(struct sockaddr_in6))
+#    define sin_set_length(s)  ((s)->sin_len = sizeof(struct sockaddr_in))
+#    define sin6_set_length(s) ((s)->sin6_len = sizeof(struct sockaddr_in6))
 #else
-# define sin_set_length(s)      /* empty */
-# define sin6_set_length(s)     /* empty */
+#    define sin_set_length(s)  /* empty */
+#    define sin6_set_length(s) /* empty */
 #endif
 
 /*
@@ -80,9 +80,9 @@
  * return short writes on blocking sockets.
  */
 #ifdef _WIN32
-# define socket_xwrite(fd, b, s)        send((fd), (b), (s), 0)
+#    define socket_xwrite(fd, b, s) send((fd), (b), (s), 0)
 #else
-# define socket_xwrite(fd, b, s)        xwrite((fd), (b), (s))
+#    define socket_xwrite(fd, b, s) xwrite((fd), (b), (s))
 #endif
 
 
@@ -600,8 +600,8 @@
  * anything useful.
  */
 socket_type
-network_connect_host(const char *host, unsigned short port,
-                     const char *source, time_t timeout)
+network_connect_host(const char *host, unsigned short port, const char *source,
+                     time_t timeout)
 {
     struct addrinfo hints, *ai;
     char portbuf[16];
@@ -979,7 +979,7 @@
             return false;
         return (a4.s_addr & addr_mask) == (b4.s_addr & addr_mask);
     }
-            
+
 #ifdef HAVE_INET6
     /*
      * Otherwise, if the address is IPv6, the mask is required to be a CIDR

Modified: lib/reallocarray.c
===================================================================
--- lib/reallocarray.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/reallocarray.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -34,8 +34,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
 

Modified: lib/setenv.c
===================================================================
--- lib/setenv.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/setenv.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -29,8 +29,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
 

Modified: lib/seteuid.c
===================================================================
--- lib/seteuid.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/seteuid.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if HAVE_UNISTD_H
-# include <unistd.h>
+#    include <unistd.h>
 #endif
 
 int

Modified: lib/snprintf.c
===================================================================
--- lib/snprintf.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/snprintf.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -11,8 +11,9 @@
  * that later merges with the original source are easy.  Bug fixes and
  * improvements should be sent back to the original author.
  *
- * The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * The canonical version of this file was maintained (until 2020) in the
+ * rra-c-util package, which can be found at
+ * <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  */
 
 /*
@@ -26,6 +27,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 "inn/messages.h"
@@ -65,7 +88,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
@@ -367,7 +390,8 @@
 	break;
       case 'X':
 	flags |= DP_F_UP;
-        /* fallthrough */
+        __attribute__((fallthrough));
+        /* fall through */
       case 'x':
 	flags |= DP_F_UNSIGNED;
 	if (cflags == DP_C_SHORT)
@@ -389,7 +413,8 @@
 	break;
       case 'E':
 	flags |= DP_F_UP;
-        /* fallthrough */
+        __attribute__((fallthrough));
+        /* fall through */
       case 'e':
 	if (cflags == DP_C_LDOUBLE)
 	  fvalue = va_arg (args, LDOUBLE);
@@ -399,7 +424,8 @@
 	break;
       case 'G':
 	flags |= DP_F_UP;
-        /* fallthrough */
+        __attribute__((fallthrough));
+        /* fall through */
       case 'g':
         flags |= DP_F_FP_G;
 	if (cflags == DP_C_LDOUBLE)
@@ -715,7 +741,7 @@
       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)

Modified: lib/vector.c
===================================================================
--- lib/vector.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/vector.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -25,7 +25,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2001-2006, 2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2001-2006, 2016, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2005-2006, 2008-2011, 2013-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -102,8 +102,8 @@
         vector->count = size;
     if (size == 0)
         size = 1;
-    vector->strings
-        = xreallocarray(vector->strings, size, sizeof(const char *));
+    vector->strings =
+        xreallocarray(vector->strings, size, sizeof(const char *));
     vector->allocated = size;
 }
 
@@ -328,7 +328,7 @@
         return 0;
 
     /*
-     * Walk the string looking for the first separator not preceeded by
+     * Walk the string looking for the first separator not preceded by
      * another separator (and ignore a separator at the start of the string).
      */
     for (count = 1, p = string + 1; *p != '\0'; p++)
@@ -351,8 +351,7 @@
  * are considered a single separator.  Reuse the provided vector if non-NULL.
  */
 struct vector *
-vector_split_multi(const char *string, const char *seps,
-                   struct vector *vector)
+vector_split_multi(const char *string, const char *seps, struct vector *vector)
 {
     const char *p, *start;
     size_t i, count;
@@ -550,7 +549,7 @@
     if (vector->allocated == vector->count)
         vector_resize(vector, vector->count + 1);
     vector->strings[vector->count] = NULL;
-    return execv(path, (char * const *) vector->strings);
+    return execv(path, (char *const *) vector->strings);
 }
 
 int
@@ -560,5 +559,5 @@
     if (vector->allocated == vector->count)
         cvector_resize(vector, vector->count + 1);
     vector->strings[vector->count] = NULL;
-    return execv(path, (char * const *) vector->strings);
+    return execv(path, (char *const *) vector->strings);
 }

Modified: lib/xmalloc.c
===================================================================
--- lib/xmalloc.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/xmalloc.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -102,8 +102,8 @@
 xmalloc_fail(const char *function, size_t size, const char *file, int line)
 {
     if (size == 0)
-        sysdie("failed to format output with %s at %s line %d", function,
-               file, line);
+        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);
@@ -203,7 +203,7 @@
     char *copy;
 
     /* Don't assume that the source string is nul-terminated. */
-    for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
+    for (p = s; (size_t)(p - s) < size && *p != '\0'; p++)
         ;
     length = p - s;
     copy = malloc(length + 1);
@@ -263,7 +263,7 @@
     }
     va_end(args);
 }
-#else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */
+#else  /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */
 void
 x_asprintf(char **strp, const char *fmt, ...)
 {

Modified: lib/xwrite.c
===================================================================
--- lib/xwrite.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ lib/xwrite.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -65,12 +65,12 @@
  * and it's possible the other functions may be similarly affected.
  */
 #if TESTING
-# undef pwrite
-# undef write
-# undef writev
-# define pwrite fake_pwrite
-# define write  fake_write
-# define writev fake_writev
+#    undef pwrite
+#    undef write
+#    undef writev
+#    define pwrite fake_pwrite
+#    define write  fake_write
+#    define writev fake_writev
 ssize_t fake_pwrite(int, const void *, size_t, off_t);
 ssize_t fake_write(int, const void *, size_t);
 ssize_t fake_writev(int, const struct iovec *, int);
@@ -85,7 +85,7 @@
     unsigned int count = 0;
 
     if (size == 0)
-	return 0;
+        return 0;
 
     /* Abort the write if we try ten times with no forward progress. */
     for (total = 0; total < size; total += status) {
@@ -113,7 +113,7 @@
     unsigned int count = 0;
 
     if (size == 0)
-	return 0;
+        return 0;
 
     /* Abort the write if we try ten times with no forward progress. */
     for (total = 0; total < size; total += status) {
@@ -148,7 +148,7 @@
      * writev to fail with an error we'll return.
      */
     if (iovcnt == 0)
-	return 0;
+        return 0;
     if (iovcnt < 0 || (size_t) iovcnt > SIZE_MAX / sizeof(struct iovec)) {
         errno = EINVAL;
         return -1;
@@ -158,7 +158,7 @@
     for (total = 0, i = 0; i < (unsigned int) iovcnt; i++)
         total += iov[i].iov_len;
     if (total == 0)
-	return 0;
+        return 0;
 
     /*
      * First, try just writing it all out.  Most of the time this will succeed

Modified: m4/cc-flags.m4
===================================================================
--- m4/cc-flags.m4	2020-11-12 20:10:53 UTC (rev 10395)
+++ m4/cc-flags.m4	2020-11-12 20:19:41 UTC (rev 10396)
@@ -8,7 +8,7 @@
 dnl The canonical version of this file is maintained in the rra-c-util
 dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 dnl
-dnl Copyright 2016-2018 Russ Allbery <eagle at eyrie.org>
+dnl Copyright 2016-2020 Russ Allbery <eagle at eyrie.org>
 dnl Copyright 2006, 2009, 2016
 dnl     by Internet Systems Consortium, Inc. ("ISC")
 dnl
@@ -28,9 +28,9 @@
 
 dnl Used to build the result cache name.
 AC_DEFUN([_INN_PROG_CC_FLAG_CACHE],
-[translit([inn_cv_compiler_c_$1], [-=+], [___])])
+[translit([inn_cv_compiler_c_$1], [-=+,], [____])])
 
-dnl Check whether a given flag is supported by the complier.
+dnl Check whether a given flag is supported by the compiler.
 AC_DEFUN([INN_PROG_CC_FLAG],
 [AC_REQUIRE([AC_PROG_CC])
  AC_MSG_CHECKING([if $CC supports $1])

Modified: m4/krb5.m4
===================================================================
--- m4/krb5.m4	2020-11-12 20:10:53 UTC (rev 10395)
+++ m4/krb5.m4	2020-11-12 20:19:41 UTC (rev 10396)
@@ -51,7 +51,8 @@
 dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 dnl
 dnl Written by Russ Allbery <eagle at eyrie.org>
-dnl Copyright 2005-2011, 2013-2014, 2018
+dnl Copyright 2018 Russ Allbery <eagle at eyrie.org>
+dnl Copyright 2005-2011, 2013-2014
 dnl     The Board of Trustees of the Leland Stanford Junior University
 dnl
 dnl This file is free software; the authors give unlimited permission to copy

Modified: m4/snprintf.m4
===================================================================
--- m4/snprintf.m4	2020-11-12 20:10:53 UTC (rev 10395)
+++ m4/snprintf.m4	2020-11-12 20:19:41 UTC (rev 10396)
@@ -10,8 +10,9 @@
 dnl Provides INN_FUNC_SNPRINTF, which adds snprintf.o to LIBOBJS unless a
 dnl fully working snprintf is found.
 dnl
-dnl The canonical version of this file is maintained in the rra-c-util
-dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+dnl The canonical version of this file was maintained (until 2020) in the
+dnl rra-c-util package, available at
+dnl <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 dnl
 dnl Written by Russ Allbery <eagle at eyrie.org>
 dnl Copyright 2006, 2008-2009

Modified: m4/socket.m4
===================================================================
--- m4/socket.m4	2020-11-12 20:10:53 UTC (rev 10395)
+++ m4/socket.m4	2020-11-12 20:19:41 UTC (rev 10396)
@@ -12,7 +12,7 @@
 dnl The canonical version of this file is maintained in the rra-c-util
 dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 dnl
-dnl Copyright 2017 Russ Allbery <eagle at eyrie.org>
+dnl Copyright 2017, 2020 Russ Allbery <eagle at eyrie.org>
 dnl Copyright 2008-2009, 2011
 dnl     The Board of Trustees of the Leland Stanford Junior University
 dnl Copyright 2004-2009 Internet Systems Consortium, Inc. ("ISC")

Modified: support/getrra-c-util
===================================================================
--- support/getrra-c-util	2020-11-12 20:10:53 UTC (rev 10395)
+++ support/getrra-c-util	2020-11-12 20:19:41 UTC (rev 10396)
@@ -119,7 +119,7 @@
 # define SEEK_END 2\\
 #endif\\
 " \
-                 -e "122 i \\
+                 -e "135 i \\
 /*\\
  * Handle defining fseeko and ftello.  If HAVE_FSEEKO is defined, the system\\
  * header files take care of this for us.  Otherwise, see if we're building\\
@@ -161,7 +161,16 @@
 extern int symlink(const char *, const char *);\\
 #endif\\
 " \
-               -e "163 i \\
+               -e "147 i \\
+#if !HAVE_DECL_SNPRINTF\\
+extern int snprintf(char *, size_t, const char *, ...)\\
+    __attribute__((__format__(printf, 3, 4)));\\
+#endif\\
+#if !HAVE_DECL_VSNPRINTF\\
+extern int vsnprintf(char *, size_t, const char *, va_list)\\
+    __attribute__((__format__(printf, 3, 0)));\\
+#endif" \
+               -e "164 i \\
 #if !HAVE_DECL_STRLCAT\\
 extern size_t strlcat(char *, const char *, size_t);\\
 #endif\\
@@ -246,7 +255,6 @@
 download m4/perl.m4 m4 perl.m4
 download m4/python.m4 m4 python.m4
 download m4/sasl.m4 m4 sasl.m4
-download m4/snprintf.m4 m4 snprintf.m4
 download m4/socket-unix.m4 m4 socket-unix.m4
 download m4/socket.m4 m4 socket.m4
 download m4/vamacros.m4 m4 vamacros.m4
@@ -266,7 +274,6 @@
 download portable/reallocarray.c lib reallocarray.c
 download portable/setenv.c lib setenv.c
 download portable/seteuid.c lib seteuid.c
-download portable/snprintf.c lib snprintf.c
 download portable/socket.h include/portable socket.h
 download portable/socket-unix.h include/portable socket-unix.h
 download portable/stdbool.h include/portable stdbool.h
@@ -300,7 +307,6 @@
 download tests/portable/mkstemp-t.c tests/lib mkstemp-t.c
 download tests/portable/reallocarray-t.c tests/lib reallocarray-t.c
 download tests/portable/setenv-t.c tests/lib setenv-t.c
-download tests/portable/snprintf-t.c tests/lib snprintf-t.c
 
 ##  Synchronize test suite files for utility functions from upstream.
 download tests/util/buffer-t.c tests/lib buffer-t.c

Modified: tests/lib/buffer-t.c
===================================================================
--- tests/lib/buffer-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/buffer-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2002-2004, 2006, 2014-2015 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2002-2004, 2006, 2014-2015, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2011-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -65,8 +65,8 @@
 int
 main(void)
 {
-    struct buffer one = { 0, 0, 0, NULL };
-    struct buffer two = { 0, 0, 0, NULL };
+    struct buffer one = {0, 0, 0, NULL};
+    struct buffer two = {0, 0, 0, NULL};
     struct buffer *three;
     int fd;
     char *data;
@@ -80,7 +80,7 @@
     is_int(1024, one.size, "minimum size is 1024");
     is_int(0, one.used, "used starts at 0");
     is_int(sizeof(test_string1), one.left, "left is correct");
-    is_string(test_string1, one.data, "data is corect");
+    is_string(test_string1, one.data, "data is correct");
     buffer_append(&one, test_string2, sizeof(test_string2));
     is_int(1024, one.size, "appended data doesn't change size");
     is_int(0, one.used, "or used");
@@ -96,7 +96,9 @@
     ok(memcmp(one.data + one.used, test_string2, sizeof(test_string2)) == 0,
        "and the middle data is unchanged");
     ok(memcmp(one.data + one.used + sizeof(test_string2), test_string1,
-              sizeof(test_string1)) == 0, "and the final data is correct");
+              sizeof(test_string1))
+           == 0,
+       "and the final data is correct");
     buffer_set(&one, test_string1, sizeof(test_string1));
     buffer_set(&two, test_string2, sizeof(test_string2));
     buffer_swap(&one, &two);

Modified: tests/lib/fakewrite.c
===================================================================
--- tests/lib/fakewrite.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/fakewrite.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -36,8 +36,8 @@
 
 #include <errno.h>
 
+#include "lib/fakewrite.h"
 #include "inn/macros.h"
-#include "lib/fakewrite.h"
 
 
 /*
@@ -105,7 +105,7 @@
         errno = ENOSPC;
         return -1;
     }
-    if ((size_t) (256 - offset) < total)
+    if ((size_t)(256 - offset) < total)
         total = 256 - offset;
     memcpy(write_buffer + offset, data, total);
     return total;

Modified: tests/lib/fdflag-t.c
===================================================================
--- tests/lib/fdflag-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/fdflag-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -33,8 +33,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 #include <sys/wait.h>

Modified: tests/lib/getaddrinfo-t.c
===================================================================
--- tests/lib/getaddrinfo-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/getaddrinfo-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2003-2005, 2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2003-2005, 2016, 2019 Russ Allbery <eagle at eyrie.org>
  * Copyright 2015 Julien ÉLIE <julien at trigofacile.com>
  * Copyright 2007-2009, 2011-2013
  *     The Board of Trustees of the Leland Stanford Junior University
@@ -22,8 +22,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include "tap/basic.h"
 
@@ -33,12 +33,12 @@
  * implementation.
  */
 #if AI_NUMERICSERV == 0
-# undef AI_NUMERICSERV
-# define AI_NUMERICSERV 0x0080
+#    undef AI_NUMERICSERV
+#    define AI_NUMERICSERV 0x0080
 #endif
 #if AI_NUMERICHOST == 0
-# undef AI_NUMERICHOST
-# define AI_NUMERICHOST 0x0100
+#    undef AI_NUMERICHOST
+#    define AI_NUMERICHOST 0x0100
 #endif
 
 const char *test_gai_strerror(int);
@@ -108,8 +108,7 @@
        "AI_NUMERICSERV with 25 smtp");
     ok(test_getaddrinfo(NULL, "25 ", &hints, &ai) == EAI_NONAME,
        "AI_NUMERICSERV with 25 space");
-    ok(test_getaddrinfo(NULL, "25", &hints, &ai) == 0,
-       "valid AI_NUMERICSERV");
+    ok(test_getaddrinfo(NULL, "25", &hints, &ai) == 0, "valid AI_NUMERICSERV");
     saddr = (struct sockaddr_in *) (void *) ai->ai_addr;
     is_int(htons(25), saddr->sin_port, "...right port");
     is_int(htonl(0x7f000001UL), saddr->sin_addr.s_addr, "...right address");
@@ -198,14 +197,14 @@
     }
 
     /* Hopefully this will always resolve. */
-    host = gethostbyname("www.isc.org");
+    host = gethostbyname("www.eyrie.org");
     if (host == NULL)
-        skip_block(9, "cannot look up www.isc.org");
+        skip_block(9, "cannot look up www.eyrie.org");
     else {
         hints.ai_flags = 0;
         hints.ai_socktype = SOCK_STREAM;
-        ok(test_getaddrinfo("www.isc.org", "80", &hints, &ai) == 0,
-           "lookup of www.isc.org");
+        ok(test_getaddrinfo("www.eyrie.org", "80", &hints, &ai) == 0,
+           "lookup of www.eyrie.org");
         is_int(SOCK_STREAM, ai->ai_socktype, "...right socktype");
         is_string(NULL, ai->ai_canonname, "...no canonname");
         saddr = (struct sockaddr_in *) (void *) ai->ai_addr;
@@ -215,8 +214,8 @@
         test_freeaddrinfo(ai);
 
         hints.ai_flags = AI_CANONNAME;
-        ok(test_getaddrinfo("www.isc.org", "80", &hints, &ai) == 0,
-           "lookup of www.isc.org with A_CANONNAME");
+        ok(test_getaddrinfo("www.eyrie.org", "80", &hints, &ai) == 0,
+           "lookup of www.eyrie.org with A_CANONNAME");
         ok(ai->ai_canonname != NULL, "...canonname isn't null");
         saddr = (struct sockaddr_in *) (void *) ai->ai_addr;
         is_int(htons(80), saddr->sin_port, "...right port");

Modified: tests/lib/getnameinfo-t.c
===================================================================
--- tests/lib/getnameinfo-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/getnameinfo-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -21,8 +21,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include "tap/basic.h"
 #include "inn/xmalloc.h"
@@ -32,7 +32,7 @@
 
 /* Linux doesn't provide EAI_OVERFLOW, so make up our own for testing. */
 #ifndef EAI_OVERFLOW
-# define EAI_OVERFLOW 10
+#    define EAI_OVERFLOW 10
 #endif
 
 int
@@ -107,14 +107,14 @@
     is_int(0, status, "lookup with NI_NUMERICHOST");
     is_string("10.20.30.40", node, "...and found correct IP address");
     node[0] = '\0';
-    status = test_getnameinfo(sa, sizeof(sin), node, 1, NULL, 0,
-                              NI_NUMERICHOST);
+    status =
+        test_getnameinfo(sa, sizeof(sin), node, 1, NULL, 0, NI_NUMERICHOST);
     is_int(EAI_OVERFLOW, status, "EAI_OVERFLOW with one character");
-    status = test_getnameinfo(sa, sizeof(sin), node, 11, NULL, 0,
-                              NI_NUMERICHOST);
+    status =
+        test_getnameinfo(sa, sizeof(sin), node, 11, NULL, 0, NI_NUMERICHOST);
     is_int(EAI_OVERFLOW, status, "EAI_OVERFLOW with 11 characters");
-    status = test_getnameinfo(sa, sizeof(sin), node, 12, NULL, 0,
-                              NI_NUMERICHOST);
+    status =
+        test_getnameinfo(sa, sizeof(sin), node, 12, NULL, 0, NI_NUMERICHOST);
     is_int(0, status, "fits into 12 characters");
     is_string("10.20.30.40", node, "...and found correct IP address");
 

Modified: tests/lib/inet_aton-t.c
===================================================================
--- tests/lib/inet_aton-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/inet_aton-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2000-2001, 2004, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2004, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2007-2009, 2011
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -21,8 +21,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include "tap/basic.h"
 
@@ -59,6 +59,8 @@
 {
     plan(92);
 
+    /* clang-format off */
+
     test_addr(            "0.0.0.0", 0);
     test_addr(     "127.0.0.000000", 0x7f000000U);
     test_addr(    "255.255.255.255", 0xffffffffU);
@@ -110,5 +112,7 @@
     test_fail(         "127..127");
     test_fail(      "de.ad.be.ef");
 
+    /* clang-format on */
+
     return 0;
 }

Modified: tests/lib/inet_ntoa-t.c
===================================================================
--- tests/lib/inet_ntoa-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/inet_ntoa-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2000-2001, 2004, 2016-2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2004, 2016-2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2006-2009, 2011
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -21,8 +21,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include "tap/basic.h"
 
@@ -44,11 +44,13 @@
 {
     plan(5);
 
+    /* clang-format off */
     test_addr(        "0.0.0.0", 0x0);
     test_addr(      "127.0.0.0", 0x7f000000U);
     test_addr("255.255.255.255", 0xffffffffU);
     test_addr("172.200.232.199", 0xacc8e8c7U);
     test_addr(        "1.2.3.4", 0x01020304U);
+    /* clang-format on */
 
     return 0;
 }

Modified: tests/lib/inet_ntop-t.c
===================================================================
--- tests/lib/inet_ntop-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/inet_ntop-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2006-2009, 2011
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -21,8 +21,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
 
@@ -30,7 +30,7 @@
 
 /* Some systems too old to have inet_ntop don't have EAFNOSUPPORT. */
 #ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EDOM
+#    define EAFNOSUPPORT EDOM
 #endif
 
 const char *test_inet_ntop(int, const void *, char *, socklen_t);
@@ -64,11 +64,13 @@
     ok(test_inet_ntop(AF_INET, NULL, NULL, 11) == NULL, "NULL buffer");
     is_int(ENOSPC, errno, "...with right errno");
 
+    /* clang-format off */
     test_addr(        "0.0.0.0", 0x0);
     test_addr(      "127.0.0.0", 0x7f000000U);
     test_addr("255.255.255.255", 0xffffffffU);
     test_addr("172.200.232.199", 0xacc8e8c7U);
     test_addr(        "1.2.3.4", 0x01020304U);
+    /* clang-format on */
 
     return 0;
 }

Modified: tests/lib/messages-t.c
===================================================================
--- tests/lib/messages-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/messages-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2002, 2004-2005, 2015, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2002, 2004-2005, 2015, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2012
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -57,7 +57,7 @@
     warn("warning");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test2(void *data UNUSED)
 {
     die("fatal");
@@ -70,7 +70,7 @@
     syswarn("permissions");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test4(void *data UNUSED)
 {
     errno = EACCES;
@@ -84,7 +84,7 @@
     warn("warning");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test6(void *data UNUSED)
 {
     message_program_name = "test6";
@@ -99,7 +99,7 @@
     syswarn("perms %d", 7);
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test8(void *data UNUSED)
 {
     message_program_name = "test8";
@@ -113,7 +113,7 @@
     return 10;
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test9(void *data UNUSED)
 {
     message_fatal_cleanup = return10;
@@ -120,7 +120,7 @@
     die("fatal");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test10(void *data UNUSED)
 {
     message_program_name = 0;
@@ -129,7 +129,7 @@
     sysdie("fatal perm");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test11(void *data UNUSED)
 {
     message_program_name = "test11";
@@ -139,7 +139,7 @@
     sysdie("fatal");
 }
 
-static void __attribute__((__format__(printf, 2, 0)))
+__attribute__((__format__(printf, 2, 0))) static void
 log_msg(size_t len, const char *format, va_list args, int error)
 {
     fprintf(stderr, "%lu %d ", (unsigned long) len, error);
@@ -154,7 +154,7 @@
     warn("warning");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test13(void *data UNUSED)
 {
     message_handlers_die(1, log_msg);
@@ -169,7 +169,7 @@
     syswarn("warning");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test15(void *data UNUSED)
 {
     message_handlers_die(2, log_msg, log_msg);
@@ -221,7 +221,7 @@
     debug("baz");
 }
 
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 test22(void *data UNUSED)
 {
     message_handlers_die(0);
@@ -228,15 +228,15 @@
     die("hi mom!");
 }
 
-static
-void test23(void *data UNUSED)
+static void
+test23(void *data UNUSED)
 {
     message_handlers_warn(0);
     warn("this is a test");
 }
 
-static
-void test24(void *data UNUSED)
+static void
+test24(void *data UNUSED)
 {
     notice("first");
     message_handlers_notice(0);
@@ -308,7 +308,7 @@
     is_function_output(test20, NULL, 0, "3 0 foo\n", "test20");
     is_function_output(test21, NULL, 0, "test23: baz\n", "test21");
 
-    /* Make sure that it's possible to turn off a message type entirely. */ 
+    /* Make sure that it's possible to turn off a message type entirely. */
     is_function_output(test22, NULL, 1, "", "test22");
     is_function_output(test23, NULL, 0, "", "test23");
     is_function_output(test24, NULL, 0, "first\nthird\n", "test24");

Modified: tests/lib/network/addr-ipv4-t.c
===================================================================
--- tests/lib/network/addr-ipv4-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/network/addr-ipv4-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013, 2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013, 2016, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -34,8 +34,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include "tap/basic.h"
 #include "inn/network.h"
@@ -110,6 +110,7 @@
     freeaddrinfo(ai);
 
     /* Tests for network_addr_compare. */
+    /* clang-format off */
     is_addr_compare(1, "127.0.0.1", "127.0.0.1",   NULL);
     is_addr_compare(0, "127.0.0.1", "127.0.0.2",   NULL);
     is_addr_compare(1, "127.0.0.1", "127.0.0.0",   "31");
@@ -123,8 +124,10 @@
     is_addr_compare(0, "129.0.0.0", "1.0.0.0",     "1");
     is_addr_compare(1, "129.0.0.0", "1.0.0.0",     "0");
     is_addr_compare(1, "129.0.0.0", "1.0.0.0",     "0.0.0.0");
+    /* clang-format on */
 
     /* Test some invalid addresses. */
+    /* clang-format off */
     is_addr_compare(0, "fred",      "fred",        NULL);
     is_addr_compare(0, "",          "",            NULL);
     is_addr_compare(0, "",          "",            "0");
@@ -133,6 +136,7 @@
     is_addr_compare(0, "127.0.0.1", "127.0.0.1",   "1p");
     is_addr_compare(0, "127.0.0.1", "127.0.0.1",   "-1");
     is_addr_compare(0, "127.0.0.1", "127.0.0.1",   "33");
+    /* clang-format on */
 
     /* Test setting various socket options. */
     fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);

Modified: tests/lib/network/addr-ipv6-t.c
===================================================================
--- tests/lib/network/addr-ipv6-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/network/addr-ipv6-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013, 2016-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013, 2016-2018, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -34,8 +34,8 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <ctype.h>
 
@@ -136,6 +136,7 @@
     freeaddrinfo(ai4);
 
     /* Tests for network_addr_compare. */
+    /* clang-format off */
     is_addr_compare(1, ipv6_addr,   ipv6_addr,     NULL);
     is_addr_compare(1, ipv6_addr,   ipv6_addr,     "128");
     is_addr_compare(1, ipv6_addr,   ipv6_addr,     "60");
@@ -152,6 +153,7 @@
     is_addr_compare(0, "ffff::1",   "7fff::1",     "-1");
     is_addr_compare(0, "ffff::1",   "ffff::1",     "-1");
     is_addr_compare(0, "ffff::1",   "ffff::1",     "129");
+    /* clang-format on */
 
     /* Test setting various socket options. */
     fd = socket(PF_INET6, SOCK_STREAM, IPPROTO_IP);

Modified: tests/lib/network/client-t.c
===================================================================
--- tests/lib/network/client-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/network/client-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013-2014, 2016-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013-2014, 2016-2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -34,12 +34,12 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
+#include <signal.h>
 #include <sys/wait.h>
-#include <signal.h>
 
 #include "tap/basic.h"
 #include "inn/macros.h"
@@ -52,7 +52,7 @@
  * and expects to always succeed on the connection, taking the source address
  * to pass into network_client_create.
  */
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 client_create_writer(const char *source)
 {
     socket_type fd;
@@ -82,7 +82,7 @@
  * sleeps for 10 seconds before sending another string so that timeouts can be
  * tested.  Meant to be run in a child process.
  */
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 client_delay_writer(const char *host)
 {
     socket_type fd;
@@ -105,7 +105,7 @@
  * Used to test network_write.  Connects, reads 64KB from the network, then
  * sleeps before reading another 64KB.  Meant to be run in a child process.
  */
-static void __attribute__((__noreturn__))
+__attribute__((__noreturn__)) static void
 client_delay_reader(const char *host)
 {
     char *buffer;
@@ -224,7 +224,8 @@
     socket_type fd, c;
     pid_t child;
     socket_type block[20];
-    int i, err;
+    unsigned int conn, i;
+    int err;
 
     /*
      * Create the listening socket.  We set the listening queue size to 1,
@@ -261,9 +262,9 @@
      * actually timing out, and sometimes they never do.
      */
     alarm(20);
-    for (i = 0; i < (int) ARRAY_SIZE(block); i++) {
-        block[i] = network_connect_host("127.0.0.1", 11119, NULL, 1);
-        if (block[i] == INVALID_SOCKET)
+    for (conn = 0; conn < ARRAY_SIZE(block); conn++) {
+        block[conn] = network_connect_host("127.0.0.1", 11119, NULL, 1);
+        if (block[conn] == INVALID_SOCKET)
             break;
     }
     err = socket_errno;
@@ -276,11 +277,11 @@
      * expect a failure due to timeout in a reasonable amount of time (less
      * than our 20-second alarm).
      */
-    if (i == ARRAY_SIZE(block))
+    if (conn == ARRAY_SIZE(block))
         skip_block(2, "short listen queue does not prevent connections");
     else {
-        diag("Finally timed out on socket %d", i);
-        ok(block[i] == INVALID_SOCKET, "Later connection timed out");
+        diag("Finally timed out on socket %u", conn);
+        ok(block[conn] == INVALID_SOCKET, "Later connection timed out");
         if (err == ECONNRESET || err == ECONNREFUSED)
             skip("connections rejected without timeout");
         else
@@ -292,7 +293,7 @@
     kill(child, SIGTERM);
     waitpid(child, NULL, 0);
     socket_close(c);
-    for (i--; i >= 0; i--)
+    for (i = 0; i < conn; i++)
         if (block[i] != INVALID_SOCKET)
             socket_close(block[i]);
     socket_close(fd);
@@ -415,8 +416,7 @@
      */
     socket_set_errno(0);
     ok(network_write(c, buffer, 32 * 1024, 0), "network_write");
-    ok(network_write(c, buffer, 32 * 1024, 1),
-       "network_write with timeout");
+    ok(network_write(c, buffer, 32 * 1024, 1), "network_write with timeout");
 
     /*
      * A longer write cannot be completely absorbed before the client sleep,

Modified: tests/lib/network/server-t.c
===================================================================
--- tests/lib/network/server-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/network/server-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013, 2016-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013, 2016-2018, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -34,12 +34,12 @@
 #define LIBTEST_NEW_FORMAT 1
 
 #include "config.h"
+#include "portable/socket.h"
 #include "clibrary.h"
-#include "portable/socket.h"
 
 #include <errno.h>
+#include <signal.h>
 #include <sys/wait.h>
-#include <signal.h>
 
 #include "tap/basic.h"
 #include "inn/fdflag.h"
@@ -150,14 +150,14 @@
  * localhost, from the given source address, containing a constant string.
  * This also verifies that network_client_create works properly.
  */
-static void __attribute__((__noreturn__))
-client_udp_writer(const char *source)
+__attribute__((__noreturn__)) static void
+client_ipv4_udp_writer(const char *source)
 {
     socket_type fd;
     struct sockaddr_in sin;
 
     /* Create and bind the socket. */
-    fd = network_client_create(PF_INET, SOCK_DGRAM, source);
+    fd = network_client_create(AF_INET, SOCK_DGRAM, source);
     if (fd == INVALID_SOCKET)
         _exit(1);
 
@@ -177,6 +177,42 @@
 
 
 /*
+ * The same as client_ipv4_udp_writer, but sents the packet via IPv6 instead.
+ * If somehow this was called without IPv6 being available (which should be
+ * impossible), do nothing and exit with a non-zero status.
+ */
+__attribute__((__noreturn__)) static void
+client_ipv6_udp_writer(const char *source)
+{
+#ifdef HAVE_INET6
+    socket_type fd;
+    struct sockaddr_in6 sin6;
+
+    /* Create and bind the socket. */
+    fd = network_client_create(AF_INET6, SOCK_DGRAM, source);
+    if (fd == INVALID_SOCKET)
+        _exit(1);
+
+    /* Connect to localhost port 11119. */
+    memset(&sin6, 0, sizeof(sin6));
+    sin6.sin6_family = AF_INET6;
+    sin6.sin6_port = htons(11119);
+    if (inet_pton(AF_INET6, "::1", &sin6.sin6_addr) < 1)
+        sysbail("cannot convert ::1 to an in6_addr");
+    if (connect(fd, (struct sockaddr *) &sin6, sizeof(sin6)) < 0)
+        _exit(1);
+
+    /* Send our fixed UDP packet. */
+    if (send(fd, "socket test\r\n", 13, 0) < 13)
+        _exit(1);
+    _exit(0);
+#else
+    _exit(1);
+#endif
+}
+
+
+/*
  * When testing the bind (server) functions, we create listening sockets, fork
  * a child process to connect to it, and accept the connection and read the
  * data in the server.  The test reporting is therefore done by the listener.
@@ -236,16 +272,17 @@
 
 
 /*
- * A varient version of the server portion of the test.  Takes an array of
+ * A variant version of the server portion of the test.  Takes an array of
  * sockets and the size of the sockets and accepts a connection on any of
  * those sockets.  Ensures that the client address information is stored
- * correctly by checking that it is an IPv4 address.  For skipping purposes,
- * this produces three tests.
+ * correctly by checking that it is an IPv4 or IPv6 address.  For skipping
+ * purposes, this produces three tests.
  *
  * Normally, the client address should be 127.0.0.1, but hosts with odd local
  * networking setups may rewrite client IP addresses so that they appear to
- * come from other addresses.  Avoid checking if the client IP is 127.0.0.1
- * for that reason.  Hopefully this won't hide bugs.
+ * come from other addresses.  Hosts that only have IPv6 interfaces will see a
+ * client connection on ::1 instead.  Avoid checking if the client IP is
+ * 127.0.0.1 for that reason.  Hopefully this won't hide bugs.
  *
  * saddr is allocated from the heap instead of using a local struct
  * sockaddr_storage to work around a misdiagnosis of strict aliasing
@@ -267,7 +304,10 @@
     saddr = bcalloc(1, slen);
     client = network_accept_any(fds, count, saddr, &slen);
     test_server_connection(client);
-    is_int(AF_INET, saddr->sa_family, "...address family is IPv4");
+    if (saddr->sa_family == AF_INET)
+        is_int(AF_INET, saddr->sa_family, "...address family is IPv4");
+    else
+        is_int(AF_INET6, saddr->sa_family, "...address family is IPv6");
     free(saddr);
     for (i = 0; i < count; i++)
         socket_close(fds[i]);
@@ -432,9 +472,9 @@
                 client_writer("127.0.0.1", source_ipv4, true);
 #ifdef HAVE_INET6
             } else if (family == AF_INET6) {
-# ifdef IPV6_V6ONLY
+#    ifdef IPV6_V6ONLY
                 client_writer("127.0.0.1", source_ipv4, false);
-# endif
+#    endif
                 client_writer("::1", source_ipv6, true);
 #endif
             } else {
@@ -465,20 +505,37 @@
     socket_type *fds;
     unsigned int count, i;
     pid_t child;
-    int status;
+    int status, family;
+    struct sockaddr *saddr;
 
+    /* Bind our socket.
+     *
+     * If the host has no IPv4 addresses, we may have only an IPv6 socket and
+     * thus can't us an IPv4 client.  Determine the address family of the
+     * first socket so that we can use an appropriate client.
+     */
     if (!network_bind_all(SOCK_STREAM, 11119, &fds, &count))
         sysbail("cannot create or bind socket");
+    saddr = get_sockaddr(fds[0]);
+    family = saddr->sa_family;
+    free(saddr);
     ok(1, "network_accept_any test");
+
+    /* Listen on all bound sockets. */
     for (i = 0; i < count; i++)
         if (listen(fds[i], 1) < 0)
             sysbail("cannot listen to socket %d", fds[i]);
+
+    /* Write a packet from a client and receive it on the server. */
     child = fork();
     if (child < 0)
         sysbail("cannot fork");
-    else if (child == 0)
-        client_writer("127.0.0.1", NULL, true);
-    else {
+    else if (child == 0) {
+        if (family == AF_INET)
+            client_writer("127.0.0.1", NULL, true);
+        else
+            client_writer("::1", NULL, true);
+    } else {
         test_server_accept_any(fds, count);
         waitpid(child, &status, 0);
         is_int(0, status, "client made correct connections");
@@ -501,22 +558,34 @@
     pid_t child;
     char buffer[BUFSIZ];
     ssize_t length;
-    int status;
+    int status, family;
     struct sockaddr_storage addr;
     struct sockaddr *saddr;
-    struct sockaddr_in sin;
     socklen_t addrlen;
 
-    /* Bind our UDP socket. */
+    /*
+     * Bind our UDP socket.
+     *
+     * If the host has no IPv4 addresses, we may have only an IPv6 socket and
+     * thus can't us an IPv4 client.  Determine the address family of the
+     * first socket so that we can use an appropriate client.
+     */
     if (!network_bind_all(SOCK_DGRAM, 11119, &fds, &count))
         sysbail("cannot create or bind socket");
+    saddr = get_sockaddr(fds[0]);
+    family = saddr->sa_family;
+    free(saddr);
 
     /* Create a child that writes a single UDP packet to the server. */
     child = fork();
     if (child < 0)
         sysbail("cannot fork");
-    else if (child == 0)
-        client_udp_writer("127.0.0.1");
+    else if (child == 0) {
+        if (family == AF_INET)
+            client_ipv4_udp_writer("127.0.0.1");
+        else
+            client_ipv6_udp_writer("::1");
+    }
 
     /* Set an alarm, since if the client malfunctions, nothing happens. */
     alarm(5);
@@ -531,19 +600,7 @@
         addrlen = sizeof(addr);
         length = recvfrom(fd, buffer, sizeof(buffer), 0, saddr, &addrlen);
         is_int(13, length, "...of correct length");
-        sin.sin_family = AF_INET;
-        sin.sin_port = htons(11119);
-
-        /*
-         * We'd prefer to check that the client IP address is 127.0.0.1 here,
-         * but hosts with odd local networking setups may rewrite the client
-         * IP address to something else.  To avoid false positives, just
-         * blindly trust the client IP address is correct, since it seems
-         * unlikely we'll have a server code bug here.
-         */
-        sin.sin_addr = ((struct sockaddr_in *) &addr)->sin_addr;
-        ok(network_sockaddr_equal((struct sockaddr *) &sin, saddr),
-           "...from correct family and port");
+        is_int(family, saddr->sa_family, "...from correct family");
         buffer[13] = '\0';
         is_string("socket test\r\n", buffer, "...and correct contents");
     }

Modified: tests/lib/snprintf-t.c
===================================================================
--- tests/lib/snprintf-t.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/snprintf-t.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -2,11 +2,12 @@
  *
  * snprintf test suite.
  *
- * The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * The canonical version of this file was maintained (until 2020) in the
+ * rra-c-util package, which can be found at
+ * <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2000-2006, 2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2006, 2018-2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2010
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright 1995 Patrick Powell
@@ -31,7 +32,7 @@
  * formats for easy testing.
  */
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || defined(__clang__)
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#    pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
 
 /*
@@ -43,20 +44,12 @@
 
 static const char string[] = "abcdefghijklmnopqrstuvwxyz0123456789";
 
+/* clang-format off */
+
 static const char *const fp_formats[] = {
-    "%-1.5f",   "%1.5f",    "%31.9f",   "%10.5f",   "% 10.5f",  "%+22.9f",
-    "%+4.9f",   "%01.3f",   "%3.1f",    "%3.2f",    "%.0f",     "%.1f",
+    "%-1.5f",   "%1.5f",    "%31.6f",   "%10.5f",   "% 10.5f",  "%+22.6f",
+    "%+4.6f",   "%01.3f",   "%3.1f",    "%3.2f",    "%.0f",     "%.1f",
     "%f",
-
-    /* %e and %g formats aren't really implemented yet. */
-#if 0
-    "%-1.5e",   "%1.5e",    "%31.9e",   "%10.5e",   "% 10.5e",  "%+22.9e",
-    "%+4.9e",   "%01.3e",   "%3.1e",    "%3.2e",    "%.0e",     "%.1e",
-    "%e",
-    "%-1.5g",   "%1.5g",    "%31.9g",   "%10.5g",   "% 10.5g",  "%+22.9g",
-    "%+4.9g",   "%01.3g",   "%3.1g",    "%3.2g",    "%.0g",     "%.1g",
-    "%g",
-#endif
     NULL
 };
 static const char *const int_formats[] = {
@@ -102,10 +95,12 @@
     0
 };
 
+/* clang-format on */
 
+
 static void
-test_format(bool trunc, const char *expected, int count,
-            const char *format, ...)
+test_format(bool trunc, const char *expected, int count, const char *format,
+            ...)
 {
     char buf[128];
     int result;
@@ -127,12 +122,13 @@
     long lcount;
     char lgbuf[128];
 
-    plan(8 +
-         (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums)
-          + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums)
-          + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums)
-          + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums)
-          + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums)) * 2);
+    plan(8
+         + (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums)
+            + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums)
+            + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums)
+            + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums)
+            + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums))
+               * 2);
 
     is_int(4, test_snprintf(NULL, 0, "%s", "abcd"), "simple string length");
     is_int(2, test_snprintf(NULL, 0, "%d", 20), "number length");
@@ -159,8 +155,8 @@
                 string, -2.5);
     test_format(true, "abcdefghij4444", 14, "%.10s%n%d", string, &count, 4444);
     is_int(10, count, "correct output from %%n");
-    test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln",
-                &count, string, &lcount);
+    test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln", &count,
+                string, &lcount);
     is_int(0, count, "correct output from two %%n");
     is_int(31, lcount, "correct output from long %%ln");
     test_format(true, "(null)", 6, "%s", (char *) NULL);

Modified: tests/lib/xmalloc.c
===================================================================
--- tests/lib/xmalloc.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/xmalloc.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -5,7 +5,7 @@
  * The canonical version of this file is maintained in the rra-c-util package,
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
- * Copyright 2000-2001, 2006, 2017 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2006, 2017, 2020 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2012-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -37,10 +37,11 @@
 #include "config.h"
 #include "clibrary.h"
 
+#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+#    include <sys/time.h>
 #endif
 #include <time.h>
 
@@ -97,6 +98,7 @@
     char *buffer;
     size_t i;
 
+    assert(size > 10);
     buffer = xmalloc(10);
     if (buffer == NULL)
         return 0;
@@ -104,8 +106,7 @@
     buffer = xrealloc(buffer, size);
     if (buffer == NULL)
         return 0;
-    if (size > 0)
-        memset(buffer + 10, 2, size - 10);
+    memset(buffer + 10, 2, size - 10);
     for (i = 0; i < 10; i++)
         if (buffer[i] != 1)
             return 0;
@@ -386,6 +387,7 @@
 #endif
     }
 
+    /* clang-format off */
     switch (code) {
     case 'c': exit(test_calloc(size) ? willfail : 1);
     case 'm': exit(test_malloc(size) ? willfail : 1);
@@ -397,5 +399,7 @@
     case 'v': exit(test_vasprintf(size) ? willfail : 1);
     default:  die("Unknown mode %c", argv[1][0]);
     }
+    /* clang-format on */
+
     exit(1);
 }

Modified: tests/lib/xmalloc.t
===================================================================
--- tests/lib/xmalloc.t	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/lib/xmalloc.t	2020-11-12 20:19:41 UTC (rev 10396)
@@ -8,7 +8,8 @@
 # which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 #
 # Written by Russ Allbery <eagle at eyrie.org>
-# Copyright 2000-2001, 2006, 2014, 2016 Russ Allbery <eagle at eyrie.org>
+# Copyright 2000-2001, 2006, 2014, 2016, 2019-2020
+#     Russ Allbery <eagle at eyrie.org>
 # Copyright 2008-2010, 2012
 #     The Board of Trustees of the Leland Stanford Junior University
 #
@@ -35,7 +36,7 @@
 . "$C_TAP_SOURCE/tap/libtap.sh"
 cd "$C_TAP_BUILD/lib"
 
-# Run an xmalloc test.  Takes the description, the expectd exit status, the
+# Run an xmalloc test.  Takes the description, the expected exit status, the
 # output, and the arguments.
 ok_xmalloc () {
     local desc w_status w_output output status
@@ -103,46 +104,46 @@
 # We assume that there are enough miscellaneous allocations that an allocation
 # exactly as large as the limit will always fail.
 ok_xmalloc "malloc fail" 1 \
-    "failed to malloc 30000000 bytes at xmalloc.c line 41" \
+    "failed to malloc 30000000 bytes at xmalloc.c line 42" \
     "m" "30000000" "30000000"
 ok_xmalloc "realloc fail" 1 \
-    "failed to realloc 30000000 bytes at xmalloc.c line 69" \
+    "failed to realloc 30000000 bytes at xmalloc.c line 71" \
     "r" "30000000" "30000000"
 ok_xmalloc "reallocarray fail" 1 \
-    "failed to reallocarray 30000000 bytes at xmalloc.c line 99" \
+    "failed to reallocarray 30000000 bytes at xmalloc.c line 100" \
     "y" "30000000" "30000000"
 ok_xmalloc "strdup fail" 1 \
-    "failed to strdup 30000000 bytes at xmalloc.c line 130" \
+    "failed to strdup 30000000 bytes at xmalloc.c line 131" \
     "s" "30000000" "30000000"
 ok_xmalloc "strndup fail" 1 \
-    "failed to strndup 30000000 bytes at xmalloc.c line 176" \
+    "failed to strndup 30000000 bytes at xmalloc.c line 177" \
     "n" "30000000" "30000000"
 ok_xmalloc "calloc fail" 1 \
-    "failed to calloc 30000000 bytes at xmalloc.c line 200" \
+    "failed to calloc 30000000 bytes at xmalloc.c line 201" \
     "c" "30000000" "30000000"
 ok_xmalloc "asprintf fail" 1 \
-    "failed to asprintf 30000000 bytes at xmalloc.c line 224" \
+    "failed to asprintf 30000000 bytes at xmalloc.c line 225" \
     "a" "30000000" "30000000"
 ok_xmalloc "vasprintf fail" 1 \
-    "failed to vasprintf 30000000 bytes at xmalloc.c line 243" \
+    "failed to vasprintf 30000000 bytes at xmalloc.c line 244" \
     "v" "30000000" "30000000"
 
 # Check our custom error handler.
-ok_xmalloc "malloc custom"       1 "malloc 30000000 xmalloc.c 41" \
+ok_xmalloc "malloc custom"       1 "malloc 30000000 xmalloc.c 42" \
     "M" "30000000" "30000000"
-ok_xmalloc "realloc custom"      1 "realloc 30000000 xmalloc.c 69" \
+ok_xmalloc "realloc custom"      1 "realloc 30000000 xmalloc.c 71" \
     "R" "30000000" "30000000"
-ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 99" \
+ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 100" \
     "Y" "30000000" "30000000"
-ok_xmalloc "strdup custom"       1 "strdup 30000000 xmalloc.c 130" \
+ok_xmalloc "strdup custom"       1 "strdup 30000000 xmalloc.c 131" \
     "S" "30000000" "30000000"
-ok_xmalloc "strndup custom"      1 "strndup 30000000 xmalloc.c 176" \
+ok_xmalloc "strndup custom"      1 "strndup 30000000 xmalloc.c 177" \
     "N" "30000000" "30000000"
-ok_xmalloc "calloc custom"       1 "calloc 30000000 xmalloc.c 200" \
+ok_xmalloc "calloc custom"       1 "calloc 30000000 xmalloc.c 201" \
     "C" "30000000" "30000000"
-ok_xmalloc "asprintf custom"     1 "asprintf 30000000 xmalloc.c 224" \
+ok_xmalloc "asprintf custom"     1 "asprintf 30000000 xmalloc.c 225" \
     "A" "30000000" "30000000"
-ok_xmalloc "vasprintf custom"    1 "vasprintf 30000000 xmalloc.c 243" \
+ok_xmalloc "vasprintf custom"    1 "vasprintf 30000000 xmalloc.c 244" \
     "V" "30000000" "30000000"
 
 # Check the smaller ones again just for grins.

Modified: tests/runtests.c
===================================================================
--- tests/runtests.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/runtests.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -9,7 +9,7 @@
  * should be sent to the e-mail address below.  This program is part of C TAP
  * Harness <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
  *
- * Copyright 2000-2001, 2004, 2006-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2000-2001, 2004, 2006-2019 Russ Allbery <eagle at eyrie.org>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -94,9 +94,9 @@
 
 /* Required for fdopen(), getopt(), and putenv(). */
 #if defined(__STRICT_ANSI__) || defined(PEDANTIC)
-# ifndef _XOPEN_SOURCE
-#  define _XOPEN_SOURCE 500
-# endif
+#    ifndef _XOPEN_SOURCE
+#        define _XOPEN_SOURCE 500
+#    endif
 #endif
 
 #include <ctype.h>
@@ -121,7 +121,7 @@
 
 /* AIX 6.1 (and possibly later) doesn't have WCOREDUMP. */
 #ifndef WCOREDUMP
-# define WCOREDUMP(status) ((unsigned)(status) & 0x80)
+#    define WCOREDUMP(status) ((unsigned) (status) &0x80)
 #endif
 
 /*
@@ -130,9 +130,9 @@
  * 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
 
 /*
@@ -150,58 +150,50 @@
  * $(abs_top_builddir) respectively.
  */
 #ifndef C_TAP_SOURCE
-# define C_TAP_SOURCE NULL
+#    define C_TAP_SOURCE NULL
 #endif
 #ifndef C_TAP_BUILD
-# define C_TAP_BUILD NULL
+#    define C_TAP_BUILD NULL
 #endif
 
 /* Test status codes. */
-enum test_status {
-    TEST_FAIL,
-    TEST_PASS,
-    TEST_SKIP,
-    TEST_INVALID
-};
+enum test_status { TEST_FAIL, TEST_PASS, TEST_SKIP, TEST_INVALID };
 
 /* Really, just a boolean, but this is more self-documenting. */
-enum test_verbose {
-    CONCISE = 0,
-    VERBOSE = 1
-};
+enum test_verbose { CONCISE = 0, VERBOSE = 1 };
 
 /* Indicates the state of our plan. */
 enum plan_status {
-    PLAN_INIT,                  /* Nothing seen yet. */
-    PLAN_FIRST,                 /* Plan seen before any tests. */
-    PLAN_PENDING,               /* Test seen and no plan yet. */
-    PLAN_FINAL                  /* Plan seen after some tests. */
+    PLAN_INIT,    /* Nothing seen yet. */
+    PLAN_FIRST,   /* Plan seen before any tests. */
+    PLAN_PENDING, /* Test seen and no plan yet. */
+    PLAN_FINAL    /* Plan seen after some tests. */
 };
 
 /* Error exit statuses for test processes. */
-#define CHILDERR_DUP    100     /* Couldn't redirect stderr or stdout. */
-#define CHILDERR_EXEC   101     /* Couldn't exec child process. */
-#define CHILDERR_STDIN  102     /* Couldn't open stdin file. */
-#define CHILDERR_STDERR 103     /* Couldn't open stderr file. */
+#define CHILDERR_DUP    100 /* Couldn't redirect stderr or stdout. */
+#define CHILDERR_EXEC   101 /* Couldn't exec child process. */
+#define CHILDERR_STDIN  102 /* Couldn't open stdin file. */
+#define CHILDERR_STDERR 103 /* Couldn't open stderr file. */
 
 /* Structure to hold data for a set of tests. */
 struct testset {
-    char *file;                 /* The file name of the test. */
-    char **command;             /* The argv vector to run the command. */
-    enum plan_status plan;      /* The status of our plan. */
-    unsigned long count;        /* Expected count of tests. */
-    unsigned long current;      /* The last seen test number. */
-    unsigned int length;        /* The length of the last status message. */
-    unsigned long passed;       /* Count of passing tests. */
-    unsigned long failed;       /* Count of failing lists. */
-    unsigned long skipped;      /* Count of skipped tests (passed). */
-    unsigned long allocated;    /* The size of the results table. */
-    enum test_status *results;  /* Table of results by test number. */
-    unsigned int aborted;       /* Whether the set was aborted. */
-    unsigned int reported;      /* Whether the results were reported. */
-    int status;                 /* The exit status of the test. */
-    unsigned int all_skipped;   /* Whether all tests were skipped. */
-    char *reason;               /* Why all tests were skipped. */
+    char *file;                /* The file name of the test. */
+    char **command;            /* The argv vector to run the command. */
+    enum plan_status plan;     /* The status of our plan. */
+    unsigned long count;       /* Expected count of tests. */
+    unsigned long current;     /* The last seen test number. */
+    unsigned int length;       /* The length of the last status message. */
+    unsigned long passed;      /* Count of passing tests. */
+    unsigned long failed;      /* Count of failing lists. */
+    unsigned long skipped;     /* Count of skipped tests (passed). */
+    unsigned long allocated;   /* The size of the results table. */
+    enum test_status *results; /* Table of results by test number. */
+    unsigned int aborted;      /* Whether the set was aborted. */
+    unsigned int reported;     /* Whether the results were reported. */
+    int status;                /* The exit status of the test. */
+    unsigned int all_skipped;  /* Whether all tests were skipped. */
+    char *reason;              /* Why all tests were skipped. */
 };
 
 /* Structure to hold a linked list of test sets. */
@@ -247,12 +239,13 @@
 -------------------------- -------------- ---- ----  ------------------------";
 
 /* Include the file name and line number in malloc failures. */
-#define xcalloc(n, size)      x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size)         x_malloc((size), __FILE__, __LINE__)
-#define xstrdup(p)            x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size)     x_strndup((p), (size), __FILE__, __LINE__)
-#define xreallocarray(p, n, size) \
-    x_reallocarray((p), (n), (size), __FILE__, __LINE__)
+#define xcalloc(n, type) \
+    ((type *) x_calloc((n), sizeof(type), __FILE__, __LINE__))
+#define xmalloc(size)     ((char *) x_malloc((size), __FILE__, __LINE__))
+#define xstrdup(p)        x_strdup((p), __FILE__, __LINE__)
+#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#define xreallocarray(p, n, type) \
+    ((type *) x_reallocarray((p), (n), sizeof(type), __FILE__, __LINE__))
 
 /*
  * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
@@ -260,9 +253,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
 
 /*
@@ -273,11 +266,11 @@
  * variadic macro support.
  */
 #if !defined(__attribute__) && !defined(__alloc_size__)
-# if defined(__GNUC__) && !defined(__clang__)
-#  if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
-#   define __alloc_size__(spec, args...) /* empty */
-#  endif
-# endif
+#    if defined(__GNUC__) && !defined(__clang__)
+#        if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+#            define __alloc_size__(spec, args...) /* empty */
+#        endif
+#    endif
 #endif
 
 /*
@@ -287,7 +280,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
 
 /* Declare internal functions that benefit from compiler attributes. */
@@ -395,6 +388,9 @@
 static void *
 x_reallocarray(void *p, size_t n, size_t size, const char *file, int line)
 {
+    n = (n > 0) ? n : 1;
+    size = (size > 0) ? size : 1;
+
     if (n > 0 && UINT_MAX / n <= size)
         sysdie("realloc too large at %s line %d", file, line);
     p = realloc(p, n * size);
@@ -415,10 +411,10 @@
     size_t len;
 
     len = strlen(s) + 1;
-    p = malloc(len);
+    p = (char *) malloc(len);
     if (p == NULL)
-        sysdie("failed to strdup %lu bytes at %s line %d",
-               (unsigned long) len, file, line);
+        sysdie("failed to strdup %lu bytes at %s line %d", (unsigned long) len,
+               file, line);
     memcpy(p, s, len);
     return p;
 }
@@ -440,10 +436,10 @@
     char *copy;
 
     /* Don't assume that the source string is nul-terminated. */
-    for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
+    for (p = s; (size_t)(p - s) < size && *p != '\0'; p++)
         ;
-    len = (size_t) (p - s);
-    copy = malloc(len + 1);
+    len = (size_t)(p - s);
+    copy = (char *) malloc(len + 1);
     if (copy == NULL)
         sysdie("failed to strndup %lu bytes at %s line %d",
                (unsigned long) len, file, line);
@@ -540,7 +536,7 @@
 static const char *
 skip_whitespace(const char *p)
 {
-    while (isspace((unsigned char)(*p)))
+    while (isspace((unsigned char) (*p)))
         p++;
     return p;
 }
@@ -553,7 +549,7 @@
 static const char *
 skip_non_whitespace(const char *p)
 {
-    while (*p != '\0' && !isspace((unsigned char)(*p)))
+    while (*p != '\0' && !isspace((unsigned char) (*p)))
         p++;
     return p;
 }
@@ -671,10 +667,10 @@
      */
     if (ts->allocated == 0) {
         s = (n > 32) ? n : 32;
-        ts->results = xcalloc(s, sizeof(enum test_status));
+        ts->results = xcalloc(s, enum test_status);
     } else {
         s = (n > ts->allocated + 1024) ? n : ts->allocated + 1024;
-        ts->results = xreallocarray(ts->results, s, sizeof(enum test_status));
+        ts->results = xreallocarray(ts->results, s, enum test_status);
     }
 
     /* Set the results for the newly-allocated test array. */
@@ -788,8 +784,7 @@
  * reported status.
  */
 static void
-test_checkline(const char *line, struct testset *ts,
-               enum test_verbose verbose)
+test_checkline(const char *line, struct testset *ts, enum test_verbose verbose)
 {
     enum test_status status = TEST_PASS;
     const char *bail;
@@ -829,7 +824,7 @@
         return;
 
     /* If we haven't yet seen a plan, look for one. */
-    if (ts->plan == PLAN_INIT && isdigit((unsigned char)(*line))) {
+    if (ts->plan == PLAN_INIT && isdigit((unsigned char) (*line))) {
         if (!test_plan(line, ts, verbose))
             return;
     } else if (strncmp(line, "1..", 3) == 0) {
@@ -880,7 +875,7 @@
      * Handle directives.  We should probably do something more interesting
      * with unexpected passes of todo tests.
      */
-    while (isdigit((unsigned char)(*line)))
+    while (isdigit((unsigned char) (*line)))
         line++;
     line = skip_whitespace(line);
     if (*line == '#') {
@@ -903,10 +898,17 @@
 
     /* Good results.  Increment our various counters. */
     switch (status) {
-        case TEST_PASS: ts->passed++;   break;
-        case TEST_FAIL: ts->failed++;   break;
-        case TEST_SKIP: ts->skipped++;  break;
-        case TEST_INVALID:              break;
+    case TEST_PASS:
+        ts->passed++;
+        break;
+    case TEST_FAIL:
+        ts->failed++;
+        break;
+    case TEST_SKIP:
+        ts->skipped++;
+        break;
+    case TEST_INVALID:
+        break;
     }
     ts->current = current;
     ts->results[current - 1] = status;
@@ -1253,7 +1255,7 @@
     char *path = NULL;
     const char *bases[3], *suffix, *base;
     unsigned int i, j;
-    const char *suffixes[3] = { "-t", ".t", "" };
+    const char *suffixes[3] = {"-t", ".t", ""};
 
     /* Possible base directories. */
     bases[0] = ".";
@@ -1345,7 +1347,7 @@
     }
 
     /* Now, build the command. */
-    ts->command = xcalloc(len + 1, sizeof(char *));
+    ts->command = xcalloc(len + 1, char *);
     i = 0;
     if (use_valgrind && valgrind != NULL) {
         if (use_libtool) {
@@ -1387,7 +1389,7 @@
     struct testlist *listhead, *current;
 
     /* Create the initial container list that will hold our results. */
-    listhead = xcalloc(1, sizeof(struct testlist));
+    listhead = xcalloc(1, struct testlist);
     current = NULL;
 
     /*
@@ -1418,10 +1420,10 @@
         if (current == NULL)
             current = listhead;
         else {
-            current->next = xcalloc(1, sizeof(struct testlist));
+            current->next = xcalloc(1, struct testlist);
             current = current->next;
         }
-        current->ts = xcalloc(1, sizeof(struct testset));
+        current->ts = xcalloc(1, struct testset);
         current->ts->plan = PLAN_INIT;
 
         /* Parse the line and store the results in the testset struct. */
@@ -1453,7 +1455,7 @@
     struct testlist *listhead, *current;
 
     /* Create the initial container list that will hold our results. */
-    listhead = xcalloc(1, sizeof(struct testlist));
+    listhead = xcalloc(1, struct testlist);
     current = NULL;
 
     /* Walk the list of arguments and create test sets for them. */
@@ -1461,13 +1463,13 @@
         if (current == NULL)
             current = listhead;
         else {
-            current->next = xcalloc(1, sizeof(struct testlist));
+            current->next = xcalloc(1, struct testlist);
             current = current->next;
         }
-        current->ts = xcalloc(1, sizeof(struct testset));
+        current->ts = xcalloc(1, struct testset);
         current->ts->plan = PLAN_INIT;
         current->ts->file = xstrdup(argv[i]);
-        current->ts->command = xcalloc(2, sizeof(char *));
+        current->ts->command = xcalloc(2, char *);
         current->ts->command[0] = find_test(current->ts->file, source, build);
         current->ts->command[1] = NULL;
     }
@@ -1574,10 +1576,10 @@
         /* If the test fails, we shuffle it over to the fail list. */
         if (!succeeded) {
             if (failhead == NULL) {
-                failhead = xmalloc(sizeof(struct testset));
+                failhead = xcalloc(1, struct testlist);
                 failtail = failhead;
             } else {
-                failtail->next = xmalloc(sizeof(struct testset));
+                failtail->next = xcalloc(1, struct testlist);
                 failtail = failtail->next;
             }
             failtail->ts = ts;
@@ -1616,8 +1618,7 @@
         else
             printf("Aborted %lu test sets", aborted);
         printf(", passed %lu/%lu tests", passed, total);
-    }
-    else if (failed == 0)
+    } else if (failed == 0)
         fputs("All tests successful", stdout);
     else
         printf("Failed %lu/%lu tests, %.2f%% okay", failed, total,
@@ -1631,8 +1632,8 @@
     puts(".");
     printf("Files=%u,  Tests=%lu", count, total);
     printf(",  %.2f seconds", tv_diff(&end, &start));
-    printf(" (%.2f usr + %.2f sys = %.2f CPU)\n",
-           tv_seconds(&stats.ru_utime), tv_seconds(&stats.ru_stime),
+    printf(" (%.2f usr + %.2f sys = %.2f CPU)\n", tv_seconds(&stats.ru_utime),
+           tv_seconds(&stats.ru_stime),
            tv_sum(&stats.ru_utime, &stats.ru_stime));
     return (failed == 0 && aborted == 0);
 }

Modified: tests/tap/basic.c
===================================================================
--- tests/tap/basic.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/basic.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -14,7 +14,7 @@
  * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2009-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle at eyrie.org>
  * Copyright 2001-2002, 2004-2008, 2011-2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -46,9 +46,9 @@
 #include <stdlib.h>
 #include <string.h>
 #ifdef _WIN32
-# include <direct.h>
+#    include <direct.h>
 #else
-# include <sys/stat.h>
+#    include <sys/stat.h>
 #endif
 #include <sys/types.h>
 #include <unistd.h>
@@ -116,8 +116,8 @@
 
 /* Windows provides mkdir and rmdir under different names. */
 #ifdef _WIN32
-# define mkdir(p, m) _mkdir(p)
-# define rmdir(p)    _rmdir(p)
+#    define mkdir(p, m) _mkdir(p)
+#    define rmdir(p)    _rmdir(p)
 #endif
 
 /*
@@ -132,7 +132,7 @@
  * We can get the highest test count from testnum.
  */
 static unsigned long _planned = 0;
-static unsigned long _failed  = 0;
+static unsigned long _failed = 0;
 
 /*
  * Store the PID of the process that called plan() and only summarize
@@ -188,15 +188,15 @@
  * print_desc, which has to be done in a macro.  Assumes that format is the
  * argument immediately before the variadic arguments.
  */
-#define PRINT_DESC(prefix, format)              \
-    do {                                        \
-        if (format != NULL) {                   \
-            va_list args;                       \
-            printf("%s", prefix);               \
-            va_start(args, format);             \
-            vprintf(format, args);              \
-            va_end(args);                       \
-        }                                       \
+#define PRINT_DESC(prefix, format)  \
+    do {                            \
+        if (format != NULL) {       \
+            va_list args;           \
+            printf("%s", prefix);   \
+            va_start(args, format); \
+            vprintf(format, args);  \
+            va_end(args);           \
+        }                           \
     } while (0)
 
 
@@ -234,7 +234,7 @@
     length++;
 
     /* Create the string. */
-    result = bmalloc(length);
+    result = bcalloc_type(length, char);
     va_start(args, first);
     offset = 0;
     for (string = first; string != NULL; string = va_arg(args, const char *)) {
@@ -249,6 +249,68 @@
 
 
 /*
+ * Helper function for check_diag_files to handle a single line in a diag
+ * file.
+ *
+ * The general scheme here used is as follows: read one line of output.  If we
+ * get NULL, check for an error.  If there was one, bail out of the test
+ * program; otherwise, return, and the enclosing loop will check for EOF.
+ *
+ * If we get some data, see if it ends in a newline.  If it doesn't end in a
+ * newline, we have one of two cases: our buffer isn't large enough, in which
+ * case we resize it and try again, or we have incomplete data in the file, in
+ * which case we rewind the file and will try again next time.
+ *
+ * Returns a boolean indicating whether the last line was incomplete.
+ */
+static int
+handle_diag_file_line(struct diag_file *file, fpos_t where)
+{
+    int size;
+    size_t length;
+
+    /* Read the next line from the file. */
+    size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
+    if (fgets(file->buffer, size, file->file) == NULL) {
+        if (ferror(file->file))
+            sysbail("cannot read from %s", file->name);
+        return 0;
+    }
+
+    /*
+     * See if the line ends in a newline.  If not, see which error case we
+     * have.
+     */
+    length = strlen(file->buffer);
+    if (file->buffer[length - 1] != '\n') {
+        int incomplete = 0;
+
+        /* Check whether we ran out of buffer space and resize if so. */
+        if (length < file->bufsize - 1)
+            incomplete = 1;
+        else {
+            file->bufsize += BUFSIZ;
+            file->buffer =
+                breallocarray_type(file->buffer, file->bufsize, char);
+        }
+
+        /*
+         * On either incomplete lines or too small of a buffer, rewind
+         * and read the file again (on the next pass, if incomplete).
+         * It's simpler than trying to double-buffer the file.
+         */
+        if (fsetpos(file->file, &where) < 0)
+            sysbail("cannot set position in %s", file->name);
+        return incomplete;
+    }
+
+    /* We saw a complete line.  Print it out. */
+    printf("# %s", file->buffer);
+    return 0;
+}
+
+
+/*
  * Check all registered diag_files for any output.  We only print out the
  * output if we see a complete line; otherwise, we wait for the next newline.
  */
@@ -257,20 +319,10 @@
 {
     struct diag_file *file;
     fpos_t where;
-    size_t length;
-    int size, incomplete;
+    int incomplete;
 
     /*
-     * Walk through each file and read each line of output available.  The
-     * general scheme here used is as follows: try to read a line of output at
-     * a time.  If we get NULL, check for EOF; on EOF, advance to the next
-     * file.
-     *
-     * If we get some data, see if it ends in a newline.  If it doesn't end in
-     * a newline, we have one of two cases: our buffer isn't large enough, in
-     * which case we resize it and try again, or we have incomplete data in
-     * the file, in which case we rewind the file and will try again next
-     * time.
+     * Walk through each file and read each line of output available.
      */
     for (file = diag_files; file != NULL; file = file->next) {
         clearerr(file->file);
@@ -282,41 +334,7 @@
         /* Continue until we get EOF or an incomplete line of data. */
         incomplete = 0;
         while (!feof(file->file) && !incomplete) {
-            size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
-            if (fgets(file->buffer, size, file->file) == NULL) {
-                if (ferror(file->file))
-                    sysbail("cannot read from %s", file->name);
-                continue;
-            }
-
-            /*
-             * See if the line ends in a newline.  If not, see which error
-             * case we have.  Use UINT_MAX as a substitute for SIZE_MAX (see
-             * the comment for breallocarray).
-             */
-            length = strlen(file->buffer);
-            if (file->buffer[length - 1] != '\n') {
-                if (length < file->bufsize - 1)
-                    incomplete = 1;
-                else {
-                    if (file->bufsize >= UINT_MAX - BUFSIZ)
-                        sysbail("line too long in %s", file->name);
-                    file->bufsize += BUFSIZ;
-                    file->buffer = brealloc(file->buffer, file->bufsize);
-                }
-
-                /*
-                 * On either incomplete lines or too small of a buffer, rewind
-                 * and read the file again (on the next pass, if incomplete).
-                 * It's simpler than trying to double-buffer the file.
-                 */
-                if (fsetpos(file->file, &where) < 0)
-                    sysbail("cannot set position in %s", file->name);
-                continue;
-            }
-
-            /* We saw a complete line.  Print it out. */
-            printf("# %s", file->buffer);
+            incomplete = handle_diag_file_line(file, where);
         }
     }
 }
@@ -573,7 +591,7 @@
     if (success)
         printf("ok %lu", testnum++);
     else {
-        diag(" left: %s", !!left  ? "true" : "false");
+        diag(" left: %s", !!left ? "true" : "false");
         diag("right: %s", !!right ? "true" : "false");
         printf("not ok %lu", testnum++);
         _failed++;
@@ -633,7 +651,7 @@
     if (success)
         printf("ok %lu", testnum++);
     else {
-        diag(" left: %s", left  == NULL ? "(null)" : left);
+        diag(" left: %s", left == NULL ? "(null)" : left);
         diag("right: %s", right == NULL ? "(null)" : right);
         printf("not ok %lu", testnum++);
         _failed++;
@@ -687,8 +705,8 @@
     if (success)
         printf("ok %lu", testnum++);
     else {
-        const unsigned char *left_c  = left;
-        const unsigned char *right_c = right;
+        const unsigned char *left_c = (const unsigned char *) left;
+        const unsigned char *right_c = (const unsigned char *) right;
 
         for (i = 0; i < len; i++) {
             if (left_c[i] != right_c[i])
@@ -798,12 +816,12 @@
 {
     struct diag_file *file, *prev;
 
-    file = bcalloc(1, sizeof(struct diag_file));
+    file = bcalloc_type(1, struct diag_file);
     file->name = bstrdup(name);
     file->file = fopen(file->name, "r");
     if (file->file == NULL)
         sysbail("cannot open %s", name);
-    file->buffer = bmalloc(BUFSIZ);
+    file->buffer = bcalloc_type(BUFSIZ, char);
     file->bufsize = BUFSIZ;
     if (diag_files == NULL)
         diag_files = file;
@@ -851,7 +869,7 @@
 
     p = calloc(n, size);
     if (p == NULL)
-        sysbail("failed to calloc %lu", (unsigned long)(n * size));
+        sysbail("failed to calloc %lu", (unsigned long) (n * size));
     return p;
 }
 
@@ -922,7 +940,7 @@
     size_t len;
 
     len = strlen(s) + 1;
-    p = malloc(len);
+    p = (char *) malloc(len);
     if (p == NULL)
         sysbail("failed to strdup %lu bytes", (unsigned long) len);
     memcpy(p, s, len);
@@ -943,10 +961,10 @@
     size_t length;
 
     /* Don't assume that the source string is nul-terminated. */
-    for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
+    for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
         ;
-    length = (size_t) (p - s);
-    copy = malloc(length + 1);
+    length = (size_t)(p - s);
+    copy = (char *) malloc(length + 1);
     if (copy == NULL)
         sysbail("failed to strndup %lu bytes", (unsigned long) length);
     memcpy(copy, s, length);
@@ -966,7 +984,7 @@
 {
     char *base;
     char *path = NULL;
-    const char *envs[] = { "C_TAP_BUILD", "C_TAP_SOURCE", NULL };
+    const char *envs[] = {"C_TAP_BUILD", "C_TAP_SOURCE", NULL};
     int i;
 
     for (i = 0; envs[i] != NULL; i++) {
@@ -1041,7 +1059,7 @@
 {
     struct cleanup_func *cleanup, **last;
 
-    cleanup = bmalloc(sizeof(struct cleanup_func));
+    cleanup = bcalloc_type(1, struct cleanup_func);
     cleanup->func = func;
     cleanup->func_with_data = func_with_data;
     cleanup->data = data;

Modified: tests/tap/basic.h
===================================================================
--- tests/tap/basic.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/basic.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -6,7 +6,7 @@
  * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2009-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle at eyrie.org>
  * Copyright 2001-2002, 2004-2008, 2011-2012, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -34,9 +34,9 @@
 #ifndef TAP_BASIC_H
 #define TAP_BASIC_H 1
 
+#include <stdarg.h> /* va_list */
+#include <stddef.h> /* size_t */
 #include <tap/macros.h>
-#include <stdarg.h>             /* va_list */
-#include <stddef.h>             /* size_t */
 
 /*
  * Used for iterating through arrays.  ARRAY_SIZE returns the number of
@@ -44,8 +44,8 @@
  * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
  * legal to refer to such a pointer as long as it's never dereferenced).
  */
-#define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
-#define ARRAY_END(array)        (&(array)[ARRAY_SIZE(array)])
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+#define ARRAY_END(array)  (&(array)[ARRAY_SIZE(array)])
 
 BEGIN_DECLS
 
@@ -103,8 +103,7 @@
     __attribute__((__format__(printf, 2, 3)));
 int okv(int success, const char *format, va_list args)
     __attribute__((__format__(printf, 2, 0)));
-void skip(const char *reason, ...)
-    __attribute__((__format__(printf, 1, 2)));
+void skip(const char *reason, ...) __attribute__((__format__(printf, 1, 2)));
 
 /*
  * Report the same status on, or skip, the next count tests.  ok_block()
@@ -114,8 +113,8 @@
     __attribute__((__format__(printf, 3, 4)));
 void skip_block(unsigned long count, const char *reason, ...)
     __attribute__((__format__(printf, 2, 3)));
+
 #endif
-
 /*
  * Compare two values.  Returns true if the test passes and false if it fails.
  * is_bool takes an int since the bool type isn't fully portable yet, but
@@ -152,10 +151,8 @@
  * diag().  Nul characters are not supported in these files and will result in
  * truncated output.
  */
-void diag_file_add(const char *file)
-    __attribute__((__nonnull__));
-void diag_file_remove(const char *file)
-    __attribute__((__nonnull__));
+void diag_file_add(const char *file) __attribute__((__nonnull__));
+void diag_file_remove(const char *file) __attribute__((__nonnull__));
 
 /* Allocate memory, reporting a fatal error with bail on failure. */
 void *bcalloc(size_t, size_t)
@@ -172,6 +169,14 @@
     __attribute__((__malloc__, __nonnull__, __warn_unused_result__));
 
 /*
+ * Macros that cast the return value from b* memory functions, making them
+ * usable in C++ code and providing some additional type safety.
+ */
+#define bcalloc_type(n, type) ((type *) bcalloc((n), sizeof(type)))
+#define breallocarray_type(p, n, type) \
+    ((type *) breallocarray((p), (n), sizeof(type)))
+
+/*
  * Find a test file under C_TAP_BUILD or C_TAP_SOURCE, returning the full
  * path.  The returned path should be freed with test_file_path_free().
  */
@@ -183,8 +188,7 @@
  * Create a temporary directory relative to C_TAP_BUILD and return the path.
  * The returned path should be freed with test_tmpdir_free().
  */
-char *test_tmpdir(void)
-    __attribute__((__malloc__, __warn_unused_result__));
+char *test_tmpdir(void) __attribute__((__malloc__, __warn_unused_result__));
 void test_tmpdir_free(char *path);
 
 /*
@@ -206,8 +210,7 @@
 typedef void (*test_cleanup_func)(int, int);
 typedef void (*test_cleanup_func_with_data)(int, int, void *);
 
-void test_cleanup_register(test_cleanup_func)
-    __attribute__((__nonnull__));
+void test_cleanup_register(test_cleanup_func) __attribute__((__nonnull__));
 void test_cleanup_register_with_data(test_cleanup_func_with_data, void *)
     __attribute__((__nonnull__));
 

Modified: tests/tap/float.c
===================================================================
--- tests/tap/float.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/float.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -11,7 +11,7 @@
  * This file is part of C TAP Harness.  The current version plus supporting
  * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
  *
- * Copyright 2008, 2010, 2012-2018 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2008, 2010, 2012-2019 Russ Allbery <eagle at eyrie.org>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -36,9 +36,9 @@
 
 /* Required for isnan() and isinf(). */
 #if defined(__STRICT_ANSI__) || defined(PEDANTIC)
-# ifndef _XOPEN_SOURCE
-#  define _XOPEN_SOURCE 600
-# endif
+#    ifndef _XOPEN_SOURCE
+#        define _XOPEN_SOURCE 600
+#    endif
 #endif
 
 #include <math.h>
@@ -62,11 +62,25 @@
  * floating point implicit conversion from the isnan() and isinf() macros.
  */
 #if defined(__llvm__) || defined(__clang__)
-# pragma clang diagnostic ignored "-Wconversion"
-# pragma clang diagnostic ignored "-Wdouble-promotion"
+#    pragma clang diagnostic ignored "-Wconversion"
+#    pragma clang diagnostic ignored "-Wdouble-promotion"
 #endif
 
 /*
+ * Returns true if the two doubles are equal infinities, false otherwise.
+ * This requires a bit of machination since isinf is not required to return
+ * different values for positive and negative infinity, and we're trying to
+ * avoid direct comparisons between floating point numbers.
+ */
+static int
+is_equal_infinity(double left, double right)
+{
+    if (!isinf(left) || !isinf(right))
+        return 0;
+    return !!(left < 0) == !!(right < 0);
+}
+
+/*
  * Takes two doubles and requires they be within epsilon of each other.
  */
 int
@@ -77,8 +91,7 @@
 
     va_start(args, format);
     fflush(stderr);
-    if ((isnan(left) && isnan(right))
-        || (isinf(left) && isinf(left) == isinf(right))
+    if ((isnan(left) && isnan(right)) || is_equal_infinity(left, right)
         || fabs(left - right) <= epsilon) {
         success = 1;
         okv(1, format, args);

Modified: tests/tap/macros.h
===================================================================
--- tests/tap/macros.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/macros.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -43,9 +43,9 @@
  * the other attributes to work with GCC versions between 2.7 and 2.96.
  */
 #ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
-#  define __attribute__(spec)   /* empty */
-# endif
+#    if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
+#        define __attribute__(spec) /* empty */
+#    endif
 #endif
 
 /*
@@ -56,18 +56,18 @@
  * variadic macro support.
  */
 #if !defined(__attribute__) && !defined(__alloc_size__)
-# if defined(__GNUC__) && !defined(__clang__)
-#  if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
-#   define __alloc_size__(spec, args...) /* empty */
-#  endif
-# endif
+#    if defined(__GNUC__) && !defined(__clang__)
+#        if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+#            define __alloc_size__(spec, args...) /* empty */
+#        endif
+#    endif
 #endif
 
 /* Suppress __warn_unused_result__ if gcc is too old. */
 #if !defined(__attribute__) && !defined(__warn_unused_result__)
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
-#  define __warn_unused_result__ /* empty */
-# endif
+#    if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+#        define __warn_unused_result__ /* empty */
+#    endif
 #endif
 
 /*
@@ -77,7 +77,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
 
 /* Used for unused parameters to silence gcc warnings. */
@@ -90,11 +90,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 /* TAP_MACROS_H */

Modified: tests/tap/process.c
===================================================================
--- tests/tap/process.c	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/process.c	2020-11-12 20:19:41 UTC (rev 10396)
@@ -49,11 +49,11 @@
 #include <fcntl.h>
 #include <signal.h>
 #ifdef HAVE_SYS_SELECT_H
-# include <sys/select.h>
+#    include <sys/select.h>
 #endif
 #include <sys/stat.h>
 #ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+#    include <sys/time.h>
 #endif
 #include <sys/wait.h>
 #include <time.h>
@@ -64,7 +64,7 @@
 
 /* May be defined by the build system. */
 #ifndef PATH_FAKEROOT
-# define PATH_FAKEROOT ""
+#    define PATH_FAKEROOT ""
 #endif
 
 /* How long to wait for the process to start in seconds. */
@@ -75,12 +75,12 @@
  * everything required to stop the process and clean up after it.
  */
 struct process {
-    pid_t pid;                  /* PID of child process */
-    char *pidfile;              /* PID file to delete on process stop */
-    char *tmpdir;               /* Temporary directory for log file */
-    char *logfile;              /* Log file of process output */
-    bool is_child;              /* Whether we can waitpid for process */
-    struct process *next;       /* Next process in global list */
+    pid_t pid;            /* PID of child process */
+    char *pidfile;        /* PID file to delete on process stop */
+    char *tmpdir;         /* Temporary directory for log file */
+    char *logfile;        /* Log file of process output */
+    bool is_child;        /* Whether we can waitpid for process */
+    struct process *next; /* Next process in global list */
 };
 
 /*

Modified: tests/tap/process.h
===================================================================
--- tests/tap/process.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/process.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -63,8 +63,7 @@
  * successfully, call bail, with the error message being the output from the
  * program.
  */
-void run_setup(const char *const argv[])
-    __attribute__((__nonnull__));
+void run_setup(const char *const argv[]) __attribute__((__nonnull__));
 
 /*
  * process_start starts a process in the background, returning an opaque data

Modified: tests/tap/string.h
===================================================================
--- tests/tap/string.h	2020-11-12 20:10:53 UTC (rev 10395)
+++ tests/tap/string.h	2020-11-12 20:19:41 UTC (rev 10396)
@@ -37,7 +37,7 @@
 #include "config.h"
 #include "tap/macros.h"
 
-#include <stdarg.h>             /* va_list */
+#include <stdarg.h> /* va_list */
 
 BEGIN_DECLS
 



More information about the inn-committers mailing list