From 95e63d55bb3343b8efc7ae5cd5cdc99fed95ce73 Mon Sep 17 00:00:00 2001
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Wed, 15 May 2024 12:27:22 +0200
Subject: [PATCH] Adjust printf codes for 64-bit time_t on 32-bit systems

Convert to long long and use %lld for printing.
Use %lld and read to long long when scanning string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/tlog/json_msg.c  | 6 ++++--
 lib/tlog/json_sink.c | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/tlog/json_msg.c b/lib/tlog/json_msg.c
index 5174c93b..ae900ff4 100644
--- a/lib/tlog/json_msg.c
+++ b/lib/tlog/json_msg.c
@@ -172,8 +172,10 @@ tlog_json_msg_init(struct tlog_json_msg *msg, struct json_object *obj)
     if (str == NULL) {
         msg->time = TLOG_TIMESPEC_ZERO;
     } else {
-        rc = sscanf(str, "%ld.%03ld",
-                    &msg->time.tv_sec, &msg->time.tv_nsec);
+        long long tv_sec;
+
+        rc = sscanf(str, "%lld.%03ld", &tv_sec, &msg->time.tv_nsec);
+        msg->time.tv_sec = tv_sec;
         if (rc < 1) {
             return TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TIME;
         }
diff --git a/lib/tlog/json_sink.c b/lib/tlog/json_sink.c
index 2b617896..3baa5a2a 100644
--- a/lib/tlog/json_sink.c
+++ b/lib/tlog/json_sink.c
@@ -219,7 +219,7 @@ tlog_json_sink_flush(struct tlog_sink *sink)
             "\"session\":"  "%u,"
             "\"id\":"       "%zu,"
             "\"pos\":"      "%s,"
-            "\"time\":"     "%ld.%03ld,"
+            "\"time\":"     "%lld.%03ld,"
             "\"timing\":"   "\"%.*s\","
             "\"in_txt\":"   "\"%.*s\","
             "\"in_bin\":"   "[%.*s],"
@@ -233,7 +233,7 @@ tlog_json_sink_flush(struct tlog_sink *sink)
         json_sink->session_id,
         json_sink->message_id,
         pos_buf,
-        real_ts.tv_sec, real_ts.tv_nsec / 1000000,
+        (long long)real_ts.tv_sec, real_ts.tv_nsec / 1000000,
         (int)(json_sink->chunk.timing_ptr - json_sink->chunk.timing_buf),
         json_sink->chunk.timing_buf,
         (int)json_sink->chunk.input.txt_len, json_sink->chunk.input.txt_buf,
