Skip to content

Commit

Permalink
Make CK_ATTRIBUTE_FORMAT refer to the right arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesjer committed Jun 22, 2020
1 parent 535d2c3 commit 7ac1fcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,33 +362,31 @@ void _mark_point(const char *file, int line)
send_loc_info(file, line);
}

void _ck_assert_failed(const char *file, int line, const char *expr, ...)
void _ck_assert_failed(const char *file, int line, const char *expr,
const char *msg, ...)
{
const char *msg;
va_list ap;
char buf[BUFSIZ];
const char *to_send;

send_loc_info(file, line);

va_start(ap, expr);
msg = (const char *)va_arg(ap, char *);

/*
* If a message was passed, format it with vsnprintf.
* Otherwise, print the expression as is.
*/
if(msg != NULL)
{
va_list ap;
va_start(ap, msg);
vsnprintf(buf, BUFSIZ, msg, ap);
va_end(ap);
to_send = buf;
}
else
{
to_send = expr;
}

va_end(ap);
send_failure_info(to_send);
if(cur_fork_status() == CK_FORK)
{
Expand Down
13 changes: 7 additions & 6 deletions src/check.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED)
*/
#define fail_if(expr, ...)\
(expr) ? \
_ck_assert_failed(__FILE__, __LINE__, "Failure '"#expr"' occurred" , ## __VA_ARGS__, NULL) \
_ck_assert_failed(__FILE__, __LINE__, "Failure '"#expr"' occurred" , ## __VA_ARGS__) \
: _mark_point(__FILE__, __LINE__)

/*
Expand All @@ -500,11 +500,12 @@ static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED)
*/
#if @HAVE_FORK@
CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
const char *expr,
...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(gnu_printf, 3, 4);
const char *expr, const char *msg,
...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(gnu_printf, 4, 5);
#else
CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
const char *expr, ...) CK_ATTRIBUTE_FORMAT(gnu_printf, 3, 4);
const char *expr, const char *msg,
...) CK_ATTRIBUTE_FORMAT(gnu_printf, 4, 5);
#endif

/**
Expand Down Expand Up @@ -534,7 +535,7 @@ CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
#define ck_assert_msg(expr, ...) \
(expr) ? \
_mark_point(__FILE__, __LINE__) : \
_ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL)
_ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__)

/**
* Unconditionally fail the test
Expand All @@ -553,7 +554,7 @@ CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
*
* @since 0.9.6
*/
#define ck_abort_msg(...) _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
#define ck_abort_msg(...) _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__)

/* Signed and unsigned integer comparison macros with improved output compared to ck_assert(). */
/* OP may be any comparison operator. */
Expand Down

0 comments on commit 7ac1fcb

Please sign in to comment.