From: Steffan Karger Date: Sun, 20 Dec 2015 10:44:09 +0000 (+0100) Subject: Make assert_failed() print the failed condition X-Git-Tag: v2.4_alpha1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b36bd40d393620cce83392f4a56392ba391fb7c;p=thirdparty%2Fopenvpn.git Make assert_failed() print the failed condition Easy change to make logging output more useful. v2: don't print the failed condition if ENABLE_SMALL is defined. Signed-off-by: Steffan Karger Acked-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <1450608249-9947-1-git-send-email-steffan@karger.me> URL: http://article.gmane.org/gmane.network.openvpn.devel/10862 Signed-off-by: Gert Doering --- diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 66f37f3b9..cfd5a418e 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -394,9 +394,12 @@ dont_mute (unsigned int flags) } void -assert_failed (const char *filename, int line) +assert_failed (const char *filename, int line, const char *condition) { - msg (M_FATAL, "Assertion failed at %s:%d", filename, line); + if (condition) + msg (M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, condition); + else + msg (M_FATAL, "Assertion failed at %s:%d", filename, line); _exit(1); } diff --git a/src/openvpn/error.h b/src/openvpn/error.h index 1dc086407..dd5ccf701 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -211,9 +211,14 @@ const char *msg_flags_string (const unsigned int flags, struct gc_arena *gc); FILE *msg_fp(const unsigned int flags); /* Fatal logic errors */ -#define ASSERT(x) do { if (!(x)) assert_failed(__FILE__, __LINE__); } while (false) +#ifndef ENABLE_SMALL +#define ASSERT(x) do { if (!(x)) assert_failed(__FILE__, __LINE__, #x); } while (false) +#else +#define ASSERT(x) do { if (!(x)) assert_failed(__FILE__, __LINE__, NULL); } while (false) +#endif -void assert_failed (const char *filename, int line) __attribute__((__noreturn__)); +void assert_failed (const char *filename, int line, const char *condition) + __attribute__((__noreturn__)); #ifdef ENABLE_DEBUG void crash (void); /* force a segfault (debugging only) */