Skip to content

Commit 39e509b

Browse files
committed
lib-imap: fix for systems with signed 32-bit time_t
The code and tests have some hard-coded values based on the size of time_t but they don't take into account whether or not time_t is a signed value. On systems such as i686 with time_t as a signed 32-bit integer, the maximum value is the same as an unsigned 31-bit integer. Adjust the code to account for this.
1 parent 6e065b7 commit 39e509b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/lib-imap/imap-date.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,17 @@ static bool tm_is_too_large(const struct tm *tm, time_t *max_time_r)
8686

8787
if (max_time == 0) {
8888
#if TIME_T_MAX_BITS == 32
89+
#ifdef TIME_T_SIGNED
90+
max_time = 0x7fffffffL;
91+
#else
8992
max_time = 0xffffffffUL;
93+
#endif
9094
#elif TIME_T_MAX_BITS == 64
95+
#ifdef TIME_T_SIGNED
96+
max_time = 0x7fffffffffffffffLL;
97+
#else
9198
max_time = 0xffffffffffffffffULL;
99+
#endif
92100
#else
93101
max_time = ((time_t)1 << TIME_T_MAX_BITS) - 1;
94102
#endif

src/lib-imap/test-imap-date.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static void test_imap_date(void)
1515
} tests[] = {
1616
{ "01-Jan-1970", 0 },
1717
{ "19-Jan-2038", 2147472000 },
18-
#if TIME_T_MAX_BITS >= 32
18+
#if TIME_T_MAX_BITS > 32 || (TIME_T_MAX_BITS == 32 && !defined(TIME_T_SIGNED))
1919
{ "07-Feb-2106", 4294944000 },
2020
#endif
2121
#if TIME_T_MAX_BITS >= 37
@@ -25,7 +25,7 @@ static void test_imap_date(void)
2525
{ "31-Dec-9999", 253402214400LL },
2626
#endif
2727
/* conversions to maximum values */
28-
#if TIME_T_MAX_BITS == 31
28+
#if TIME_T_MAX_BITS == 31 || (TIME_T_MAX_BITS == 32 && defined(TIME_T_SIGNED))
2929
{ "20-Jan-2038", 2147483647 },
3030
{ "31-Dec-9999", 2147483647 },
3131
#elif TIME_T_MAX_BITS == 32
@@ -60,7 +60,7 @@ static void test_imap_datetime(void)
6060
{ "01-Jan-1970 00:00:00 +0000", 0, 0 },
6161
{ "19-Jan-2038 03:14:07 +0000", 2147483647, 0 },
6262
{ "19-Jan-2038 05:14:07 +0200", 2147483647, 2*60 },
63-
#if TIME_T_MAX_BITS >= 32
63+
#if TIME_T_MAX_BITS > 32 || (TIME_T_MAX_BITS == 32 && !defined(TIME_T_SIGNED))
6464
{ "07-Feb-2106 06:28:15 +0000", 4294967295, 0 },
6565
#endif
6666
#if TIME_T_MAX_BITS >= 37
@@ -71,7 +71,7 @@ static void test_imap_datetime(void)
7171
{ "31-Dec-9999 23:59:59 -2359", 253402300799LL + 23*60*60 + 59*60, -23*60 - 59 },
7272
#endif
7373
/* conversions to maximum values */
74-
#if TIME_T_MAX_BITS == 31
74+
#if TIME_T_MAX_BITS == 31 || (TIME_T_MAX_BITS == 32 && defined(TIME_T_SIGNED))
7575
{ "19-Jan-2038 03:14:08 +0000", 2147483647, 0 },
7676
{ "31-Dec-9999 23:59:59 -2359", 2147483647, -23*60 - 59 },
7777
#elif TIME_T_MAX_BITS == 32

0 commit comments

Comments
 (0)