]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Make assert_failed() print the failed condition
authorSteffan Karger <steffan@karger.me>
Sun, 20 Dec 2015 10:44:09 +0000 (11:44 +0100)
committerGert Doering <gert@greenie.muc.de>
Sun, 20 Dec 2015 13:08:07 +0000 (14:08 +0100)
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 <steffan@karger.me>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
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 <gert@greenie.muc.de>
src/openvpn/error.c
src/openvpn/error.h

index 66f37f3b9a411fe3675c667196780beb0f598ab6..cfd5a418e622af873250cb6fda674b3bd8f5243a 100644 (file)
@@ -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);
 }
 
index 1dc08640718f7c443423003770b4141e9134a918..dd5ccf701777540c94d85195bb06f053ee4e19a5 100644 (file)
@@ -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) */