From 308f4efb1ff4f02c263c9106a2e0d7fa395f3a2f Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Mon, 27 Jan 2025 11:33:07 +0200 Subject: [PATCH] lib-var-expand: test-var-expand - Initialize tm before strptime() strptime() only sets what it parses, this test will fail if localtime_r() and strptime() disagree on the local timezone, so use localtime_r() to initialize tm with current tz to ensure they will. --- src/lib-var-expand/test-var-expand.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib-var-expand/test-var-expand.c b/src/lib-var-expand/test-var-expand.c index c31696fe68..a87815678f 100644 --- a/src/lib-var-expand/test-var-expand.c +++ b/src/lib-var-expand/test-var-expand.c @@ -456,6 +456,10 @@ static void test_var_expand_providers(void) { /* try to parse result */ struct tm tm; i_zero(&tm); + /* get localtime to ensure we are in same timezone */ + time_t t = time(NULL); + if (localtime_r(&t, &tm) == NULL) + i_panic("localtime_r() failed: %m"); if (strptime(datetime, "%Y%m%dT%H%M%S", &tm) == NULL) { test_failed(t_strdup_printf("strptime() failed: %m")); } else { -- 2.47.3