Skip to content

Commit 6e7901c

Browse files
committed
Merge branch 'clar'
Some fixes in `clar`, pointed out by CodeQL. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 16bd9f2 + adfc130 commit 6e7901c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

t/unit-tests/clar/clar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ clar_parse_args(int argc, char **argv)
558558

559559
default:
560560
clar_abort("Unexpected commandline argument '%s'.\n",
561-
argument[1]);
561+
argument);
562562
}
563563
}
564564
}
@@ -767,7 +767,7 @@ void clar__assert_equal(
767767
if (!is_equal) {
768768
if (s1 && s2) {
769769
int pos;
770-
for (pos = 0; s1[pos] == s2[pos] && pos < len; ++pos)
770+
for (pos = 0; pos < len && s1[pos] == s2[pos]; ++pos)
771771
/* find differing byte offset */;
772772
p_snprintf(buf, sizeof(buf), "'%.*s' != '%.*s' (at byte %d)",
773773
len, s1, len, s2, pos);
@@ -803,7 +803,7 @@ void clar__assert_equal(
803803
if (!is_equal) {
804804
if (wcs1 && wcs2) {
805805
int pos;
806-
for (pos = 0; wcs1[pos] == wcs2[pos] && pos < len; ++pos)
806+
for (pos = 0; pos < len && wcs1[pos] == wcs2[pos]; ++pos)
807807
/* find differing byte offset */;
808808
p_snprintf(buf, sizeof(buf), "'%.*ls' != '%.*ls' (at byte %d)",
809809
len, wcs1, len, wcs2, pos);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ static int clar_summary_testsuites(struct clar_summary *summary)
1919
return fprintf(summary->fp, "<testsuites>\n");
2020
}
2121

22+
#ifdef _WIN32
23+
static struct tm *localtime_r(const time_t *timep, struct tm *result)
24+
{
25+
if (localtime_s(result, timep) == 0)
26+
return result;
27+
return NULL;
28+
}
29+
#endif
30+
2231
static int clar_summary_testsuite(struct clar_summary *summary,
2332
int idn, const char *name, time_t timestamp,
2433
int test_count, int fail_count, int error_count)
2534
{
26-
struct tm *tm = localtime(&timestamp);
35+
struct tm tm;
2736
char iso_dt[20];
2837

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

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

0 commit comments

Comments
 (0)