summaryrefslogtreecommitdiff
path: root/libarchive
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 /libarchive
parent673d82c57ca7dd098dfd421250b0c3289825e837 (diff)
downloadlibarchive-0d7cc9a041461ba03de90476db2c9bcb0a391112.tar.gz
tests: silence localtime() CodeQL warnings
Use localtime_r() or _localtime64_s() if available
Diffstat (limited to 'libarchive')
-rw-r--r--libarchive/test/test_write_format_zip_compression_store.c23
-rw-r--r--libarchive/test/test_write_format_zip_file.c21
-rw-r--r--libarchive/test/test_write_format_zip_file_zip64.c21
3 files changed, 61 insertions, 4 deletions
diff --git a/libarchive/test/test_write_format_zip_compression_store.c b/libarchive/test/test_write_format_zip_compression_store.c
index c969a41d..ed090878 100644
--- a/libarchive/test/test_write_format_zip_compression_store.c
+++ b/libarchive/test/test_write_format_zip_compression_store.c
@@ -128,12 +128,31 @@ static void verify_uncompressed_contents(const char *buff, size_t used)
/* Misc variables */
unsigned long crc;
- struct tm *tm = localtime(&now);
-
+ struct tm *tm;
+#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
/* p is the pointer to walk over the central directory,
* q walks over the local headers, the data and the data descriptors. */
const char *p, *q, *local_header, *extra_start;
+#if defined(HAVE_LOCALTIME_R)
+ tm = localtime_r(&now, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = now;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &tmbuf;
+#else
+ tm = localtime(&now);
+#endif
+
/* Remember the end of the archive in memory. */
buffend = buff + used;
diff --git a/libarchive/test/test_write_format_zip_file.c b/libarchive/test/test_write_format_zip_file.c
index 2868123b..7796a48c 100644
--- a/libarchive/test/test_write_format_zip_file.c
+++ b/libarchive/test/test_write_format_zip_file.c
@@ -73,7 +73,14 @@ DEFINE_TEST(test_write_format_zip_file)
struct archive *a;
struct archive_entry *ae;
time_t t = 1234567890;
- struct tm *tm = localtime(&t);
+ struct tm *tm;
+#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
size_t used, buffsize = 1000000;
unsigned long crc;
int file_perm = 00644;
@@ -91,6 +98,18 @@ DEFINE_TEST(test_write_format_zip_file)
zip_compression = 0;
#endif
+#if defined(HAVE_LOCALTIME_R)
+ tm = localtime_r(&t, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = t;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &tmbuf;
+#else
+ tm = localtime(&t);
+#endif
buff = malloc(buffsize);
/* Create a new archive in memory. */
diff --git a/libarchive/test/test_write_format_zip_file_zip64.c b/libarchive/test/test_write_format_zip_file_zip64.c
index 71da9866..c4161bc3 100644
--- a/libarchive/test/test_write_format_zip_file_zip64.c
+++ b/libarchive/test/test_write_format_zip_file_zip64.c
@@ -75,7 +75,14 @@ DEFINE_TEST(test_write_format_zip_file_zip64)
struct archive *a;
struct archive_entry *ae;
time_t t = 1234567890;
- struct tm *tm = localtime(&t);
+ struct tm *tm;
+#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
size_t used, buffsize = 1000000;
unsigned long crc;
int file_perm = 00644;
@@ -92,6 +99,18 @@ DEFINE_TEST(test_write_format_zip_file_zip64)
zip_compression = 0;
#endif
+#if defined(HAVE_LOCALTIME_R)
+ tm = localtime_r(&t, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = t;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &tmbuf;
+#else
+ tm = localtime(&t);
+#endif
buff = malloc(buffsize);
/* Create a new archive in memory. */