From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: [PATCH] lib: avoid casting gint64 to time_t
Date: Wed, 24 Jun 2020 08:04:29 -0300 [thread overview]
Message-ID: <20200624110429.178032-1-david@tethera.net> (raw)
In-Reply-To: <87o8p9nvq2.fsf@tethera.net>
This is a partial fix for problems with 64 bit timestamps on 32 bit
architectures. In certain (not completely understood by me) cases this
casting causes 32bit overflows and yields negative timestamps for
times in the far future.
In g_mime_utils_header_decode_date_unix, there is really no reason to
cast to and from time_t.
In _notmuch_message_set_header_values, we rely on implicit casting of
the argument to Xapian::sortable_serialise to double.
---
This is not a complete fix, but at least the timestamp ends up
aparently correct in the database. It looks like there are still
wonky conversions on reading the large timestamp from the database.
lib/message.cc | 2 +-
| 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/message.cc b/lib/message.cc
index 0fa0eb3a..948626bd 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1217,7 +1217,7 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
const char *from,
const char *subject)
{
- time_t time_value;
+ gint64 time_value;
/* GMime really doesn't want to see a NULL date, so protect its
* sensibilities. */
--git a/util/gmime-extra.c b/util/gmime-extra.c
index 04d8ed3d..af7b6d52 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -192,7 +192,7 @@ gint64
g_mime_utils_header_decode_date_unix (const char *date)
{
GDateTime *parsed_date = g_mime_utils_header_decode_date (date);
- time_t ret;
+ gint64 ret;
if (parsed_date) {
ret = g_date_time_to_unix (parsed_date);
--
2.27.0
next prev parent reply other threads:[~2020-06-30 11:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 14:18 test failures on 32 bit architectures David Bremner
2020-06-22 23:12 ` David Bremner
2020-06-24 0:39 ` David Bremner
2020-06-24 11:04 ` David Bremner [this message]
2020-06-24 12:40 ` [PATCH] lib: avoid casting gint64 to time_t David Bremner
2020-06-24 14:32 ` [PATCH 1/2] configure: detect 64 bit time_t David Bremner
2020-06-24 14:32 ` [PATCH 2/2] test: mark two tests broken on machines with 32 " David Bremner
2020-06-27 1:25 ` David Bremner
2020-06-24 19:38 ` [PATCH 1/2] configure: detect 64 " Tomi Ollila
2020-06-27 1:25 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200624110429.178032-1-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).