Skip to content

Commit

Permalink
clar: use size_t to keep track of current line number
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Jul 5, 2019
1 parent 2dea473 commit 77d7e5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tests/clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fixture_path(const char *base, const char *fixture_name);

struct clar_error {
const char *file;
int line_number;
size_t line_number;
const char *error_msg;
char *description;

Expand Down Expand Up @@ -589,7 +589,7 @@ void clar__skip(void)

void clar__fail(
const char *file,
int line,
size_t line,
const char *error_msg,
const char *description,
int should_abort)
Expand Down Expand Up @@ -621,7 +621,7 @@ void clar__fail(
void clar__assert(
int condition,
const char *file,
int line,
size_t line,
const char *error_msg,
const char *description,
int should_abort)
Expand All @@ -634,7 +634,7 @@ void clar__assert(

void clar__assert_equal(
const char *file,
int line,
size_t line,
const char *err,
int should_abort,
const char *fmt,
Expand Down
6 changes: 3 additions & 3 deletions tests/clar.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ void clar__skip(void);

void clar__fail(
const char *file,
int line,
size_t line,
const char *error,
const char *description,
int should_abort);

void clar__assert(
int condition,
const char *file,
int line,
size_t line,
const char *error,
const char *description,
int should_abort);

void clar__assert_equal(
const char *file,
int line,
size_t line,
const char *err,
int should_abort,
const char *fmt,
Expand Down
2 changes: 1 addition & 1 deletion tests/clar/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void clar_print_error(int num, const struct clar_report *report, const st
{
printf(" %d) Failure:\n", num);

printf("%s::%s [%s:%d]\n",
printf("%s::%s [%s:%"PRIuZ"]\n",
report->suite,
report->test,
error->file,
Expand Down

0 comments on commit 77d7e5e

Please sign in to comment.