Skip to content

Commit 77d7e5e

Browse files
committed
clar: use size_t to keep track of current line number
We use the `__LINE__` macro in several places throughout clar to allow easier traceability when e.g. a test fails. While `__LINE__` is of type `size_t`, the clar functions all accept an integer and thus may loose precision. While unlikely that any file in our codebase will exceed a linecount of `INT_MAX`, let's convert it anyway to silence any compiler warnings.
1 parent 2dea473 commit 77d7e5e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

tests/clar.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fixture_path(const char *base, const char *fixture_name);
9696

9797
struct clar_error {
9898
const char *file;
99-
int line_number;
99+
size_t line_number;
100100
const char *error_msg;
101101
char *description;
102102

@@ -589,7 +589,7 @@ void clar__skip(void)
589589

590590
void clar__fail(
591591
const char *file,
592-
int line,
592+
size_t line,
593593
const char *error_msg,
594594
const char *description,
595595
int should_abort)
@@ -621,7 +621,7 @@ void clar__fail(
621621
void clar__assert(
622622
int condition,
623623
const char *file,
624-
int line,
624+
size_t line,
625625
const char *error_msg,
626626
const char *description,
627627
int should_abort)
@@ -634,7 +634,7 @@ void clar__assert(
634634

635635
void clar__assert_equal(
636636
const char *file,
637-
int line,
637+
size_t line,
638638
const char *err,
639639
int should_abort,
640640
const char *fmt,

tests/clar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ void clar__skip(void);
141141

142142
void clar__fail(
143143
const char *file,
144-
int line,
144+
size_t line,
145145
const char *error,
146146
const char *description,
147147
int should_abort);
148148

149149
void clar__assert(
150150
int condition,
151151
const char *file,
152-
int line,
152+
size_t line,
153153
const char *error,
154154
const char *description,
155155
int should_abort);
156156

157157
void clar__assert_equal(
158158
const char *file,
159-
int line,
159+
size_t line,
160160
const char *err,
161161
int should_abort,
162162
const char *fmt,

tests/clar/print.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void clar_print_error(int num, const struct clar_report *report, const st
2020
{
2121
printf(" %d) Failure:\n", num);
2222

23-
printf("%s::%s [%s:%d]\n",
23+
printf("%s::%s [%s:%"PRIuZ"]\n",
2424
report->suite,
2525
report->test,
2626
error->file,

0 commit comments

Comments
 (0)