]> git.notmuchmail.org Git - notmuch/commitdiff
sprinter: change integer method to use int64_t
authorPeter Wang <novalazy@gmail.com>
Sat, 8 Feb 2020 01:49:22 +0000 (12:49 +1100)
committerDavid Bremner <david@tethera.net>
Thu, 13 Feb 2020 23:10:42 +0000 (19:10 -0400)
In particular, timestamps beyond 2038 could overflow the sprinter
interface on systems where time_t is 64-bit but 'int' is a signed 32-bit
integer type.

sprinter-json.c
sprinter-sexp.c
sprinter-text.c
sprinter.h
test/T160-json.sh

index c6ec857720d9e6acd0c0c4b9410afaa391249606..273bdeca3d736dcb16f90acdf4ee6377efb281d0 100644 (file)
@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <talloc.h>
@@ -124,11 +125,11 @@ json_string (struct sprinter *sp, const char *val)
 }
 
 static void
-json_integer (struct sprinter *sp, int val)
+json_integer (struct sprinter *sp, int64_t val)
 {
     struct sprinter_json *spj = json_begin_value (sp);
 
-    fprintf (spj->stream, "%d", val);
+    fprintf (spj->stream, "%"PRId64, val);
 }
 
 static void
index 6891ea4254f82e89b9758f0fb6921901f00377b3..35c007d5a25f55d7bcebae9c588b5a6d35d1a615 100644 (file)
@@ -18,6 +18,7 @@
  * Author: Peter Feigl <peter.feigl@gmx.at>
  */
 
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <talloc.h>
@@ -161,11 +162,11 @@ sexp_keyword (struct sprinter *sp, const char *val)
 }
 
 static void
-sexp_integer (struct sprinter *sp, int val)
+sexp_integer (struct sprinter *sp, int64_t val)
 {
     struct sprinter_sexp *sps = sexp_begin_value (sp);
 
-    fprintf (sps->stream, "%d", val);
+    fprintf (sps->stream, "%"PRId64, val);
 }
 
 static void
index 648b54b1e886553cd839ca24f4f5f0a9378aa47b..7b68f98ccbb17e7a494cbc925e954af6347e3b91 100644 (file)
@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <talloc.h>
@@ -44,11 +45,11 @@ text_string (struct sprinter *sp, const char *val)
 }
 
 static void
-text_integer (struct sprinter *sp, int val)
+text_integer (struct sprinter *sp, int64_t val)
 {
     struct sprinter_text *sptxt = (struct sprinter_text *) sp;
 
-    fprintf (sptxt->stream, "%d", val);
+    fprintf (sptxt->stream, "%"PRId64, val);
 }
 
 static void
index 182b1a8ba705e6493a1c5b51b7cc1518f71dfd8a..528d8a2db332bdaea6801424a15f7ca42db673ec 100644 (file)
@@ -33,7 +33,7 @@ typedef struct sprinter {
      */
     void (*string)(struct sprinter *, const char *);
     void (*string_len)(struct sprinter *, const char *, size_t);
-    void (*integer)(struct sprinter *, int);
+    void (*integer)(struct sprinter *, int64_t);
     void (*boolean)(struct sprinter *, bool);
     void (*null)(struct sprinter *);
 
index ec1b5adb4a7edfd312b9f78c2bf8aa605b6877bb..d975efa7191e69b3edf251aced2a6c8084c30dcc 100755 (executable)
@@ -65,7 +65,6 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
  \"unread\"]}]"
 
 test_begin_subtest "Search message: json, 64-bit timestamp"
-test_subtest_known_broken
 add_message "[subject]=\"json-search-64bit-timestamp-subject\"" "[date]=\"Tue, 01 Jan 2999 12:00:00 -0000\"" "[body]=\"json-search-64bit-timestamp-message\""
 output=$(notmuch search --format=json "json-search-64bit-timestamp-message" | notmuch_search_sanitize)
 test_expect_equal_json "$output" "[{\"thread\": \"XXX\",