Here is a patch to disable assert() by default and remove all the exit() calls.

It turns out, there is a built in mechanism for disabling assert in
the assert.h header itself.
You just need to define NDEBUG.  I checked on several platforms, they
all use NDEBUG.

I changed configure.ac to add NDEBUG to CFLAGS if none of the
--with-debug* options are passed.

NDEBUG disables all asserts including the ones in the asn1 directory,
the channels directory, everywhere.

plus, I added the configure options

--with-debug-assert - to turn on ASSERT() macro
--with-debug-stream-assert - to turn on ASSERT_AVAILABLE() macro

of course, these options(like all --with-debug*) cause NDEBUG to NOT be defined.

Jay
From 75fa3d1ffe451707e5b1c7decd1dd5c0b3a67c4d Mon Sep 17 00:00:00 2001
From: Jay Sorg <jay.s...@gmail.com>
Date: Sat, 15 Jan 2011 23:02:08 -0800
Subject: [PATCH] disable asserts by deafult and remove all exit()

---
 configure.ac        |   54 ++++++++++++++++++++++++++++++++++++++++----------
 libfreerdp/cache.c  |    1 -
 libfreerdp/debug.h  |    2 +-
 libfreerdp/orders.c |    7 +++--
 libfreerdp/secure.c |    2 +-
 libfreerdp/stream.h |    2 +-
 6 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index e27dbe1..07c136b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,8 @@ AH_TEMPLATE(WITH_DEBUG_RDP5, [Turn on debugging messages])
 AH_TEMPLATE(WITH_DEBUG_SCARD, [Turn on debugging messages])
 AH_TEMPLATE(WITH_DEBUG_SERIAL, [Turn on debugging messages])
 AH_TEMPLATE(WITH_DEBUG_SOUND, [Turn on debugging messages])
+AH_TEMPLATE(WITH_DEBUG_ASSERT, [Turn on debugging messages])
+AH_TEMPLATE(WITH_DEBUG_STREAM_ASSERT, [Turn on debugging messages])
 
 AC_PROG_INSTALL
 AC_PROG_LIBTOOL
@@ -759,7 +761,8 @@ AC_ARG_WITH(debug,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-kbd,
@@ -768,7 +771,8 @@ AC_ARG_WITH(debug-kbd,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG_KBD,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-rdp5,
@@ -777,7 +781,8 @@ AC_ARG_WITH(debug-rdp5,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG_RDP5,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-sound,
@@ -786,7 +791,8 @@ AC_ARG_WITH(debug-sound,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG_SOUND,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-channel,
@@ -795,7 +801,8 @@ AC_ARG_WITH(debug-channel,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG_CHANNEL,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-serial,
@@ -804,7 +811,8 @@ AC_ARG_WITH(debug-serial,
         if test $withval != "no";
         then
             AC_DEFINE(WITH_DEBUG_SERIAL,1)
-	fi
+            debug_support=yes
+        fi
     ])
 
 AC_ARG_WITH(debug-smartcard,
@@ -812,12 +820,37 @@ AC_ARG_WITH(debug-smartcard,
     [
         if test $withval != "no";
         then
-		if test x"$WITH_SCARD" = "x1"; then
-			AC_DEFINE(WITH_DEBUG_SCARD,1)
-		fi
-	fi
+          if test x"$WITH_SCARD" = "x1"; then
+            AC_DEFINE(WITH_DEBUG_SCARD,1)
+            debug_support=yes
+          fi
+        fi
+    ])
+
+AC_ARG_WITH(debug-assert,
+    [  --with-debug-assert     enable assert debugging],
+    [
+        if test $withval != "no";
+        then
+            AC_DEFINE(WITH_DEBUG_ASSERT,1)
+            debug_support=yes
+        fi
     ])
 
+AC_ARG_WITH(debug-stream-assert,
+    [  --with-debug-stream-assert     enable stream assert debugging],
+    [
+        if test $withval != "no";
+        then
+            AC_DEFINE(WITH_DEBUG_STREAM_ASSERT,1)
+            debug_support=yes
+        fi
+    ])
+
+if test "$debug_support" != "yes"; then
+    CFLAGS="$CFLAGS -DNDEBUG"
+fi
+
 #
 # target-specific stuff
 #
@@ -943,4 +976,3 @@ echo "Printer      : $printer"
 echo "CUnit        : $cunit"
 echo "X11          : $x11"
 echo "DirectFB     : $dfb"
-
diff --git a/libfreerdp/cache.c b/libfreerdp/cache.c
index bee433b..2ab9b52 100644
--- a/libfreerdp/cache.c
+++ b/libfreerdp/cache.c
@@ -82,7 +82,6 @@ cache_rebuild_bmpcache_linked_list(rdpCache * cache, uint8 id, sint16 * idx, int
 	{
 		ui_error(cache->rdp->inst, "Oops. %d in bitmap cache linked list, %d in ui "
 			 "cache...\n", c, cache->bmpcache_count[id]);
-		exit(1);
 	}
 }
 
diff --git a/libfreerdp/debug.h b/libfreerdp/debug.h
index 459d2ad..e5c5af8 100644
--- a/libfreerdp/debug.h
+++ b/libfreerdp/debug.h
@@ -5,7 +5,7 @@
 #include "config.h"
 #endif
 
-#ifndef DISABLE_ASSERT
+#ifdef WITH_DEBUG_ASSERT
 #include <assert.h>
 #define ASSERT(a)	assert(a)
 #else
diff --git a/libfreerdp/orders.c b/libfreerdp/orders.c
index 333ec7d..21f9187 100644
--- a/libfreerdp/orders.c
+++ b/libfreerdp/orders.c
@@ -1501,13 +1501,13 @@ process_create_offscr_bitmap(rdpOrders * orders, STREAM s)
 }
 
 /* Process a non-standard order */
-static void
+static int
 process_alternate_secondary_order(rdpOrders * orders, STREAM s, uint8 order_flags)
 {
 	if (!(order_flags & 0x2))
 	{
 		perror("order parsing failed\n");
-		exit(1);
+		return 1;
 	}
 	order_flags >>= 2;
 	switch (order_flags)
@@ -1520,8 +1520,9 @@ process_alternate_secondary_order(rdpOrders * orders, STREAM s, uint8 order_flag
 			break;
 		default:
 			ui_unimpl(orders->rdp->inst, "alternate secondary order %d:\n", order_flags);
-			exit(1);
+			return 1;
 	}
+	return 0;
 }
 
 /* Process a secondary order */
diff --git a/libfreerdp/secure.c b/libfreerdp/secure.c
index e1f9ee2..6bcdc30 100644
--- a/libfreerdp/secure.c
+++ b/libfreerdp/secure.c
@@ -988,7 +988,7 @@ sec_connect(rdpSec * sec, char *server, char *username, int port)
 		sec->tls_connected = 1;
 		ntlm_send_negotiate_message(sec);
 		credssp_recv(sec);
-		exit(0); /* not implemented from this point */
+		return False; /* not implemented from this point */
 	}
 	else if(sec->negotiated_protocol == PROTOCOL_TLS)
 	{
diff --git a/libfreerdp/stream.h b/libfreerdp/stream.h
index d3779ab..e8ae8a5 100644
--- a/libfreerdp/stream.h
+++ b/libfreerdp/stream.h
@@ -59,7 +59,7 @@ typedef struct stream *STREAM;
 /* True if exactly at end */
 #define s_check_end(s)		((s)->p == (s)->end)
 
-#if WITH_DEBUG || defined(ENABLE_STREAM_CHECK)
+#ifdef WITH_DEBUG_STREAM_ASSERT
 /* Check all stream access to prevent buffer overruns. */
 #define ASSERT_AVAILABLE(s,n) ASSERT(s_check_rem(s,n))
 #else
-- 
1.6.3.3

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Freerdp-devel mailing list
Freerdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freerdp-devel

Reply via email to