]> git.notmuchmail.org Git - notmuch/commitdiff
don't pass NULL as second parameter to gzerror
authorDavid Bremner <david@tethera.net>
Sun, 12 Apr 2020 23:00:31 +0000 (20:00 -0300)
committerDavid Bremner <david@tethera.net>
Mon, 13 Apr 2020 20:13:55 +0000 (17:13 -0300)
Although (as of 1.2.11) zlib checks this parameter before writing to
it, the docs don't promise to keep doing so, so be safe.

notmuch-dump.c
notmuch-restore.c
util/zlib-extra.c
util/zlib-extra.h

index 65e026394cf77e12d9fe3ba2772c395eb789b750..af346ba296cf9ef2a357d6dd9991d2072e32e609 100644 (file)
@@ -21,7 +21,7 @@
 #include "notmuch-client.h"
 #include "hex-escape.h"
 #include "string-util.h"
-#include <zlib.h>
+#include "zlib-extra.h"
 
 static int
 database_dump_config (notmuch_database_t *notmuch, gzFile output)
@@ -316,7 +316,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
 
     ret = gzflush (output, Z_FINISH);
     if (ret) {
-       fprintf (stderr, "Error flushing output: %s\n", gzerror (output, NULL));
+       fprintf (stderr, "Error flushing output: %s\n", gzerror_str (output));
        goto DONE;
     }
 
@@ -332,7 +332,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
     ret = gzclose_w (output);
     if (ret) {
        fprintf (stderr, "Error closing %s: %s\n", name_for_error,
-                gzerror (output, NULL));
+                gzerror_str (output));
        ret = EXIT_FAILURE;
        output = NULL;
        goto DONE;
index 4b509d95ba003dd4342d2bd74ed47c67d4bca6d8..9a8b7fb59b8c50e35cbf6c32fd6dc375c3dbf465 100644 (file)
@@ -450,7 +450,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
 
     if (input && gzclose_r (input)) {
        fprintf (stderr, "Error closing %s: %s\n",
-                name_for_error, gzerror (input, NULL));
+                name_for_error, gzerror_str (input));
        ret = EXIT_FAILURE;
     }
 
index f691cccf2a336e5f2785a5daf8da7f8cc0612a25..623f6d62d1e4fc13331e9c5a56d8b005287df0bd 100644 (file)
@@ -80,7 +80,7 @@ const char *
 gz_error_string (util_status_t status, gzFile file)
 {
     if (status == UTIL_GZERROR)
-       return gzerror (file, NULL);
+       return gzerror_str (file);
     else
        return util_error_string (status);
 }
index 209fa9989437d8cf77bf9ac60c739cb9fcb47a8f..296dc91441be04e0c32fbacd7938819750930c9b 100644 (file)
@@ -27,6 +27,11 @@ gz_getline (void *ctx, char **lineptr, ssize_t *bytes_read, gzFile stream);
 const char *
 gz_error_string (util_status_t status, gzFile stream);
 
+/* Call gzerror with a dummy errno argument, the docs don't promise to
+ * support the NULL case */
+inline const char *
+gzerror_str(gzFile file) { int dummy; return gzerror (file, &dummy); }
+
 #ifdef __cplusplus
 }
 #endif