Date header parsing fails persistently due to aliasing issue in datetok()
I noticed in an optimized build of evolution on Gentoo that parsing date headers always failed. I could track this down to the datetok()
implementation in camel-mime-utils.c.
The somewhat fancy singly linked list initialization in this function seems to have aliasing issues:
datetok()
always returns NULL
in this case, the compiler does not see tokens
changing.
(A disassembly of the code confirms that e.g. a call to parse_rfc822_date
is not even present.)
This can be fixed by switching to a more conservative implementation like this, where tokens
is clearly written to:
diff --git a/src/camel/camel-mime-utils.c b/src/camel/camel-mime-utils.c
index 6d6cdd1..52707ea 100644
--- a/src/camel/camel-mime-utils.c
+++ b/src/camel/camel-mime-utils.c
@@ -4160,7 +4160,7 @@ struct _date_token {
static struct _date_token *
datetok (const gchar *date)
{
- struct _date_token *tokens = NULL, *token, *tail = (struct _date_token *) &tokens;
+ struct _date_token *tokens = NULL, *token, *tail = NULL;
const gchar *start, *end;
guchar mask;
@@ -4187,7 +4187,11 @@ datetok (const gchar *date)
token->len = end - start;
token->mask = mask;
- tail->next = token;
+ if (tail) {
+ tail->next = token;
+ } else {
+ tokens = token;
+ }
tail = token;
}
If this fix is fine for you, I can create a pull request.