From 1ea597b6e133aa96c68d76e0bf0b229059ec22d3 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 15 Feb 2024 09:25:39 -0600 Subject: [PATCH] Move time_t test later so 32-bit check of 64-bit functions can work https://github.com/Hamlib/Hamlib/issues/1478 --- src/misc.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/misc.c b/src/misc.c index bbab4946f..18723f8eb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2826,6 +2826,7 @@ char *date_strget(char *buf, int buflen, int localtime) struct tm result = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; int mytimezone; + // 2038 failure here for 32-bit time_t t = time(NULL); if (localtime) @@ -3068,12 +3069,6 @@ int rig_test_2038(RIG *rig) __MSVCRT_VERSION__); #endif - if (sizeof(time_t) == 4) - { - rig_debug(RIG_DEBUG_TRACE, "%s: ctime is null, 2038 test failed\n", __func__); - return 1; - } - int failed = 0; #if defined(__MSVCRT_VERSION__) x = (__time64_t)((1UL << 31) - 1); @@ -3082,12 +3077,26 @@ int rig_test_2038(RIG *rig) if (strlen(s) == 0) { failed = 1; } + rig_debug(RIG_DEBUG_VERBOSE, "%s: MSVCRT 2038 test = 0x%08lx:%s\n", __func__, x, + s); + #else - x = (time_t)((1U << 31) - 1); + + if (sizeof(time_t) == 4) + { + rig_debug(RIG_DEBUG_TRACE, "%s: time_t is 4 bytes, 2038 test failed\n", + __func__); + return 1; + } + + x = (time_t)((1U << 63) - 1); char *s = ctime(&x); if (s == NULL) { failed = 1; } + rig_debug(RIG_DEBUG_VERBOSE, "%s: time_t 2038 test = 0x%08lx:%s", __func__, x, + s); + #endif if (failed)