Skip to content

Commit ef3bb01

Browse files
committed
Merge branch 'clar'
Some fixes in `clar`, pointed out by CodeQL. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 76d27a6 + bfffcac commit ef3bb01

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

t/unit-tests/clar/clar.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
# else
8080
# define p_snprintf snprintf
8181
# endif
82+
83+
# define localtime_r(timer, buf) (localtime_s(buf, timer) == 0 ? buf : NULL)
8284
#else
8385
# include <sys/wait.h> /* waitpid(2) */
8486
# include <unistd.h>
@@ -558,7 +560,7 @@ clar_parse_args(int argc, char **argv)
558560

559561
default:
560562
clar_abort("Unexpected commandline argument '%s'.\n",
561-
argument[1]);
563+
argument);
562564
}
563565
}
564566
}
@@ -767,7 +769,7 @@ void clar__assert_equal(
767769
if (!is_equal) {
768770
if (s1 && s2) {
769771
int pos;
770-
for (pos = 0; s1[pos] == s2[pos] && pos < len; ++pos)
772+
for (pos = 0; pos < len && s1[pos] == s2[pos]; ++pos)
771773
/* find differing byte offset */;
772774
p_snprintf(buf, sizeof(buf), "'%.*s' != '%.*s' (at byte %d)",
773775
len, s1, len, s2, pos);
@@ -803,7 +805,7 @@ void clar__assert_equal(
803805
if (!is_equal) {
804806
if (wcs1 && wcs2) {
805807
int pos;
806-
for (pos = 0; wcs1[pos] == wcs2[pos] && pos < len; ++pos)
808+
for (pos = 0; pos < len && wcs1[pos] == wcs2[pos]; ++pos)
807809
/* find differing byte offset */;
808810
p_snprintf(buf, sizeof(buf), "'%.*ls' != '%.*ls' (at byte %d)",
809811
len, wcs1, len, wcs2, pos);

t/unit-tests/clar/clar/summary.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ static int clar_summary_testsuite(struct clar_summary *summary,
2323
int idn, const char *name, time_t timestamp,
2424
int test_count, int fail_count, int error_count)
2525
{
26-
struct tm *tm = localtime(&timestamp);
26+
struct tm tm;
2727
char iso_dt[20];
2828

29-
if (strftime(iso_dt, sizeof(iso_dt), "%Y-%m-%dT%H:%M:%S", tm) == 0)
29+
localtime_r(&timestamp, &tm);
30+
if (strftime(iso_dt, sizeof(iso_dt), "%Y-%m-%dT%H:%M:%S", &tm) == 0)
3031
return -1;
3132

3233
return fprintf(summary->fp, "\t<testsuite"

0 commit comments

Comments
 (0)