diff --git a/src/ck.c b/src/ck.c index 076690eb..a00897be 100644 --- a/src/ck.c +++ b/src/ck.c @@ -373,15 +373,31 @@ error: #endif -__attribute_noreturn__ -void -ck_bt_abort (const char *filename, unsigned int line, const char *msg) +__attribute_noinline__ +__attribute_nonnull__ +static void +ck_bt_stderr (const char *filename, unsigned int line, const char *msg, const char *fmt) { - fprintf(stderr, "%s.%u: %s\n", filename, line, msg); + fprintf(stderr, fmt, filename, line, msg); #ifdef HAVE_LIBUNWIND ck_backtrace(stderr); #endif fflush(stderr); +} + + +void +ck_bt (const char *filename, unsigned int line, const char *msg) +{ + ck_bt_stderr(filename, line, msg, "%s.%u: %s\n"); +} + + +__attribute_noreturn__ +void +ck_bt_abort (const char *filename, unsigned int line, const char *msg) +{ + ck_bt(filename, line, msg); abort(); } @@ -391,10 +407,6 @@ void ck_assert_failed(const char *filename, unsigned int line, const char *msg) { /* same as ck_bt_abort() but add "assertion failed: " prefix here * to avoid bloating string tables in callers */ - fprintf(stderr, "%s.%u: assertion failed: %s\n", filename, line, msg); - #ifdef HAVE_LIBUNWIND - ck_backtrace(stderr); - #endif - fflush(stderr); + ck_bt_stderr(filename, line, msg, "%s.%u: assertion failed: %s\n"); abort(); } diff --git a/src/ck.h b/src/ck.h index 34a7d571..3c896789 100644 --- a/src/ck.h +++ b/src/ck.h @@ -56,6 +56,12 @@ __attribute_nonnull__ int ck_memeq_const_time_fixed_len (const void *a, const void *b, size_t len); +/*(ck_bt() is not from C11 Annex K) + * ck_bt() prints backtrace to stderr */ +__attribute_cold__ +__attribute_nonnull__ +void ck_bt(const char *filename, unsigned int line, const char *msg); + /*(ck_bt_abort() is not from C11 Annex K) * ck_bt_abort() prints backtrace to stderr and calls abort() */ __attribute_cold__