aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2020-03-13 18:37:19 +0100
committerAndreas Schneider <asn@cryptomilk.org>2020-10-04 09:45:39 +0200
commita731966c628ee519a53eaf9eda66834d9800f8fa (patch)
treec1f9a7a6882815f688d30867cef37466590e06fb /src
parent9c114ac31a33217cf003bbb674c1aff7bb048917 (diff)
downloadcmocka-a731966c628ee519a53eaf9eda66834d9800f8fa.tar.gz
cmocka-a731966c628ee519a53eaf9eda66834d9800f8fa.tar.xz
cmocka-a731966c628ee519a53eaf9eda66834d9800f8fa.zip
cmocka: Add compiler attributes to non-returning functions
This introduces the CMOCKA_NORETURN macro which adds the __attribute__((noreturn)) attribute to non-returning functions. In Windows, __declspec(noreturn) is added instead. Functions that don't return but are not marked with the attribute can confuse static analysers, making them to report false positives. Add CMOCKA_NORETURN attribute to _fail(), _skip(), and to the internal exception_handler(). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmocka.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 5863a27..4b3af05 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -416,6 +416,9 @@ void _skip(const char * const file, const int line)
cm_print_error(SOURCE_LOCATION_FORMAT ": Skipped!\n", file, line);
global_skip_test = 1;
exit_test(1);
+
+ /* Unreachable */
+ exit(-1);
}
/* Initialize a SourceLocation structure. */
@@ -2290,11 +2293,14 @@ void _fail(const char * const file, const int line) {
break;
}
exit_test(1);
+
+ /* Unreachable */
+ exit(-1);
}
#ifndef _WIN32
-static void exception_handler(int sig) {
+CMOCKA_NORETURN static void exception_handler(int sig) {
const char *sig_strerror = "";
#ifdef HAVE_STRSIGNAL
@@ -2304,6 +2310,9 @@ static void exception_handler(int sig) {
cm_print_error("Test failed with exception: %s(%d)",
sig_strerror, sig);
exit_test(1);
+
+ /* Unreachable */
+ exit(-1);
}
#else /* _WIN32 */