summaryrefslogtreecommitdiff
path: root/cpio
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 /cpio
parent673d82c57ca7dd098dfd421250b0c3289825e837 (diff)
downloadlibarchive-0d7cc9a041461ba03de90476db2c9bcb0a391112.tar.gz
tests: silence localtime() CodeQL warnings
Use localtime_r() or _localtime64_s() if available
Diffstat (limited to 'cpio')
-rw-r--r--cpio/test/test_option_t.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/cpio/test/test_option_t.c b/cpio/test/test_option_t.c
index eaa73fa3..0f2dda27 100644
--- a/cpio/test/test_option_t.c
+++ b/cpio/test/test_option_t.c
@@ -36,6 +36,14 @@ DEFINE_TEST(test_option_t)
time_t mtime;
char date[32];
char date2[32];
+ 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
/* List reference archive, make sure the TOC is correct. */
extract_reference_file("test_option_t.cpio");
@@ -87,11 +95,23 @@ DEFINE_TEST(test_option_t)
#ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
#endif
+#if defined(HAVE_LOCALTIME_R)
+ tmptr = localtime_r(&mtime, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = mtime;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tmptr = NULL;
+ else
+ tmptr = &tmbuf;
+#else
+ tmptr = localtime(&mtime);
+#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
- strftime(date2, sizeof(date2)-1, "%b %d %Y", localtime(&mtime));
+ strftime(date2, sizeof(date2)-1, "%b %d %Y", tmptr);
_snprintf(date, sizeof(date)-1, "%12.12s file", date2);
#else
- strftime(date2, sizeof(date2)-1, "%b %e %Y", localtime(&mtime));
+ strftime(date2, sizeof(date2)-1, "%b %e %Y", tmptr);
snprintf(date, sizeof(date)-1, "%12.12s file", date2);
#endif
assertEqualMem(p + 42, date, strlen(date));