summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.de>2022-12-08 00:20:58 +0100
committerMartin Matuska <martin@matuska.de>2022-12-08 00:24:33 +0100
commit0d7cc9a041461ba03de90476db2c9bcb0a391112 (patch)
tree263422e4e18170e54eae9c45db2c9b1b9985f998 /test_utils
parent673d82c57ca7dd098dfd421250b0c3289825e837 (diff)
downloadlibarchive-0d7cc9a041461ba03de90476db2c9bcb0a391112.tar.gz
tests: silence localtime() CodeQL warnings
Use localtime_r() or _localtime64_s() if available
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/test_main.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index fd5c6da7..f5f5a713 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -3869,6 +3869,14 @@ main(int argc, char **argv)
int tmp2_len;
#endif
time_t now;
+ struct tm *tmptr;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__LOCALTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
char *refdir_alloc = NULL;
const char *progname;
char **saved_argv;
@@ -4103,9 +4111,20 @@ main(int argc, char **argv)
*/
now = time(NULL);
for (i = 0; ; i++) {
+#if defined(HAVE_LOCALTIME_R)
+ tmptr = localtime_r(&now, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = now;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tmptr = NULL;
+ else
+ tmptr = &tmbuf;
+#else
+ tmptr = localtime(&now);
+#endif
strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
- "%Y-%m-%dT%H.%M.%S",
- localtime(&now));
+ "%Y-%m-%dT%H.%M.%S", tmptr);
if ((strlen(tmp) + 1 + strlen(progname) + 1 +
strlen(tmpdir_timestamp) + 1 + 3) >
(sizeof(tmpdir) / sizeof(char))) {