Skip to content

Commit 3fea1af

Browse files
utests - call tzset after setenv TZ
unit-tests can fail if run in an env where TZ is already set. This is because utest.h setup calls setenv("TZ"), but does not call tzset() immediately after that. This causes tzname, timezone, and daylight global variables to by out of sync from the newly set environment value of "TZ". To fix this, explicitly call tzset(). It's unlikely that a program would call setenv("TZ") during it's lifetime, and this should ideally only happen in a test env.
1 parent 9d64cd6 commit 3fea1af

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tests/utests/utests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,8 @@ utest_setup(void **state)
13261326

13271327
/* set CET */
13281328
setenv("TZ", "CET+02:00", 1);
1329+
/* call tzset explicitly, to update the tzname, timezone and daylight global variables */
1330+
tzset();
13291331

13301332
return 0;
13311333
}

0 commit comments

Comments
 (0)