From 5f9330466c6b1572210a82846ed3bf63d29eea0c Mon Sep 17 00:00:00 2001 From: brarcher Date: Tue, 17 Dec 2013 03:28:26 +0000 Subject: [PATCH] check.h: only mark _ck_assert_failed as noreturn when using fork When fork is used, _ck_assert_failed will call exit() when a failure occurs. Marking it as noreturn makes sense in this case. When fork() is not used, longjmp() is called, which is a type of return. Marking it as noreturn allows the compiler (gcc) to make assumptions which are not true. Using longjmp causes the unit testing program to segfault. For this reason, the function is only marked as noreturn when using fork(). Any static source code analysis to catch issues must be done on a system with fork() to avoid possible false positives. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@871 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- src/check.h.in | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/check.h.in b/src/check.h.in index d14056e..f4a68de 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -265,8 +265,20 @@ static void __testname (int _i CK_ATTRIBUTE_UNUSED)\ #define fail ck_abort_msg -/* This is called whenever an assertion fails */ +/* + * This is called whenever an assertion fails. + * Note that it only has the noreturn modifier when + * using fork. If fork is unavailable, the function + * calls longjmp() when a test assertion fails. Marking + * the function as noreturn causes gcc to make assumptions + * which are not valid, as longjmp() is like a return. + */ +#if @HAVE_FORK@ void CK_EXPORT _ck_assert_failed (const char *file, int line, const char *expr, ...) CK_ATTRIBUTE_NORETURN; +#else +void CK_EXPORT _ck_assert_failed (const char *file, int line, const char *expr, ...); +#endif +; /* New check fail API. */ -- 2.40.0