From: Aki Tuomi Date: Mon, 27 Jan 2025 09:33:07 +0000 (+0200) Subject: lib-var-expand: test-var-expand - Initialize tm before strptime() X-Git-Tag: 2.4.1~277 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=308f4efb1ff4f02c263c9106a2e0d7fa395f3a2f;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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 {