Change in libosmocore[master]: osmo_panic(): Annotate as __attribute__ ((noreturn))

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Jun 29 18:28:01 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/9788


Change subject: osmo_panic(): Annotate as __attribute__ ((noreturn))
......................................................................

osmo_panic(): Annotate as __attribute__ ((noreturn))

In Change-Id I5a70eb65952cbc329bf96eacb428b07a9da32433 we redirected
all OSMO_ASSERT() via osmo_panic().  However, this caused various
applications to have build failures, as OSMO_ASSERT() now appeared
to be able to return to the call site.  Let's inform the compiler
explicitly that there's no return from osmo_panic().

Change-Id: I8adf4c7b0ee6a4581cef8dd4e9f6a1dfde70ee55
---
M include/osmocom/core/panic.h
M src/panic.c
2 files changed, 12 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/9788/1

diff --git a/include/osmocom/core/panic.h b/include/osmocom/core/panic.h
index 2bb4240..e6a5bb5 100644
--- a/include/osmocom/core/panic.h
+++ b/include/osmocom/core/panic.h
@@ -7,9 +7,9 @@
 #include <stdarg.h>
 
 /*! panic handler callback function type */
-typedef void (*osmo_panic_handler_t)(const char *fmt, va_list args);
+typedef void (*osmo_panic_handler_t)(const char *fmt, va_list args) __attribute__((noreturn));
 
-extern void osmo_panic(const char *fmt, ...);
+extern void osmo_panic(const char *fmt, ...) __attribute__ ((noreturn));
 extern void osmo_set_panic_handler(osmo_panic_handler_t h);
 
 /*! @} */
diff --git a/src/panic.c b/src/panic.c
index a08f89f..61d1840 100644
--- a/src/panic.c
+++ b/src/panic.c
@@ -27,6 +27,7 @@
  *  @{
  * \file panic.c */
 
+#include <unistd.h>
 #include <osmocom/core/panic.h>
 #include <osmocom/core/backtrace.h>
 
@@ -50,6 +51,8 @@
 
 #else
 
+static void osmo_panic_default(const char *fmt, va_list args) __attribute__ ((noreturn));
+
 static void osmo_panic_default(const char *fmt, va_list args)
 {
 	while (1);
@@ -83,8 +86,14 @@
 		osmo_panic_default(fmt, args);
 
 	va_end(args);
+
+	/* not reached, but make compiler believe we really never return */
+#ifndef PANIC_INFLOOP
+	exit(2342);
+#else
+	while (1) ;
+#endif
 }
- 
 
 /*! Set the panic handler
  *  \param[in] h New panic handler function

-- 
To view, visit https://gerrit.osmocom.org/9788
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8adf4c7b0ee6a4581cef8dd4e9f6a1dfde70ee55
Gerrit-Change-Number: 9788
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180629/749366a3/attachment.htm>


More information about the gerrit-log mailing list