[PATCH 04/15] lib/thread: sort sibling messages by date

David Bremner david at tethera.net
Mon Sep 3 08:18:02 PDT 2018


Tomi Ollila <tomi.ollila at iki.fi> writes:

>> +static int
>> +_cmpmsg (const void *pa, const void *pb)
>> +{
>> +    notmuch_message_t **a = (notmuch_message_t **) pa;
>> +    notmuch_message_t **b = (notmuch_message_t **) pb;
>> +    time_t time_a = notmuch_message_get_date (*a);
>> +    time_t time_b = notmuch_message_get_date (*b);
>> +
>> +    return (int) difftime (time_a, time_b);
>
> time_t is often 64 bits now (and I suspect signed). int is often 32-bits 
> (gcc -dM -E -xc /dev/null | grep -i size to verify), perhaps time_t as
> return value ?
>

The return type is defined as int by the qsort prototype.

What we care about here is the sign. I think it's better to just avoid
difftime

-    return (int) difftime (time_a, time_b);
+    if (time_a == time_b)
+       return 0;
+    else if (time_a < time_b)
+       return -1;
+    else
+       return 1;
 }




More information about the notmuch mailing list