INN commit: trunk (12 files)

INN Commit rra at isc.org
Wed Sep 4 17:48:25 UTC 2019


    Date: Wednesday, September 4, 2019 @ 10:48:24
  Author: iulius
Revision: 10346

Update to latest C TAP Harness and RRA C Util upstream releases

Modified:
  trunk/lib/getaddrinfo.c
  trunk/lib/inet_aton.c
  trunk/m4/cc-flags.m4
  trunk/m4/krb5.m4
  trunk/tests/lib/getaddrinfo-t.c
  trunk/tests/lib/network/client-t.c
  trunk/tests/lib/xmalloc.c
  trunk/tests/lib/xmalloc.t
  trunk/tests/runtests.c
  trunk/tests/tap/basic.c
  trunk/tests/tap/basic.h
  trunk/tests/tap/float.c

------------------------------+
 lib/getaddrinfo.c            |   10 +--
 lib/inet_aton.c              |    6 -
 m4/cc-flags.m4               |    2 
 m4/krb5.m4                   |    3 
 tests/lib/getaddrinfo-t.c    |   14 ++--
 tests/lib/network/client-t.c |   19 +++--
 tests/lib/xmalloc.c          |    5 -
 tests/lib/xmalloc.t          |   34 +++++-----
 tests/runtests.c             |   39 ++++++------
 tests/tap/basic.c            |  130 +++++++++++++++++++++++------------------
 tests/tap/basic.h            |   10 ++-
 tests/tap/float.c            |   18 +++++
 12 files changed, 167 insertions(+), 123 deletions(-)

Modified: lib/getaddrinfo.c
===================================================================
--- lib/getaddrinfo.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ lib/getaddrinfo.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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 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
@@ -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;
 }
 

Modified: lib/inet_aton.c
===================================================================
--- lib/inet_aton.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ lib/inet_aton.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2011, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -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;

Modified: m4/cc-flags.m4
===================================================================
--- m4/cc-flags.m4	2019-09-04 17:47:27 UTC (rev 10345)
+++ m4/cc-flags.m4	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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-2019 Russ Allbery <eagle at eyrie.org>
 dnl Copyright 2006, 2009, 2016
 dnl     by Internet Systems Consortium, Inc. ("ISC")
 dnl

Modified: m4/krb5.m4
===================================================================
--- m4/krb5.m4	2019-09-04 17:47:27 UTC (rev 10345)
+++ m4/krb5.m4	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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: tests/lib/getaddrinfo-t.c
===================================================================
--- tests/lib/getaddrinfo-t.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/lib/getaddrinfo-t.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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
@@ -198,14 +198,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 +215,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/network/client-t.c
===================================================================
--- tests/lib/network/client-t.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/lib/network/client-t.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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-2019 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009-2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -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);

Modified: tests/lib/xmalloc.c
===================================================================
--- tests/lib/xmalloc.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/lib/xmalloc.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -37,6 +37,7 @@
 #include "config.h"
 #include "clibrary.h"
 
+#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #ifdef HAVE_SYS_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;

Modified: tests/lib/xmalloc.t
===================================================================
--- tests/lib/xmalloc.t	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/lib/xmalloc.t	2019-09-04 17:48:24 UTC (rev 10346)
@@ -8,7 +8,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, 2006, 2014, 2016 Russ Allbery <eagle at eyrie.org>
+# Copyright 2000-2001, 2006, 2014, 2016, 2019 Russ Allbery <eagle at eyrie.org>
 # Copyright 2008-2010, 2012
 #     The Board of Trustees of the Leland Stanford Junior University
 #
@@ -103,46 +103,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	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/runtests.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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"),
@@ -247,12 +247,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 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, size) \
-    x_reallocarray((p), (n), (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
@@ -415,7 +416,7 @@
     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);
@@ -443,7 +444,7 @@
     for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
         ;
     len = (size_t) (p - s);
-    copy = malloc(len + 1);
+    copy = (char *) malloc(len + 1);
     if (copy == NULL)
         sysdie("failed to strndup %lu bytes at %s line %d",
                (unsigned long) len, file, line);
@@ -671,10 +672,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. */
@@ -1345,7 +1346,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 +1388,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 +1419,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 +1454,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 +1462,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 +1575,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;

Modified: tests/tap/basic.c
===================================================================
--- tests/tap/basic.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/tap/basic.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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
  *
@@ -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);
         }
     }
 }
@@ -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;
@@ -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);
@@ -946,7 +964,7 @@
     for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
         ;
     length = (size_t) (p - s);
-    copy = malloc(length + 1);
+    copy = (char *) malloc(length + 1);
     if (copy == NULL)
         sysbail("failed to strndup %lu bytes", (unsigned long) length);
     memcpy(copy, s, length);
@@ -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	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/tap/basic.h	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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
  *
@@ -172,6 +172,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().
  */

Modified: tests/tap/float.c
===================================================================
--- tests/tap/float.c	2019-09-04 17:47:27 UTC (rev 10345)
+++ tests/tap/float.c	2019-09-04 17:48:24 UTC (rev 10346)
@@ -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"),
@@ -67,6 +67,20 @@
 #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
@@ -78,7 +92,7 @@
     va_start(args, format);
     fflush(stderr);
     if ((isnan(left) && isnan(right))
-        || (isinf(left) && isinf(left) == isinf(right))
+        || is_equal_infinity(left, right)
         || fabs(left - right) <= epsilon) {
         success = 1;
         okv(1, format, args);



More information about the inn-committers mailing list