]> mj.ucw.cz Git - libucw.git/commitdiff
lib.h: Added ASSERT_READABLE and ASSERT_WRITEABLE
authorMartin Mares <mj@ucw.cz>
Sat, 18 Feb 2012 12:08:07 +0000 (13:08 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 18 Feb 2012 12:08:07 +0000 (13:08 +0100)
ucw/lib.h

index f1ea7e9dc4fdb44f11d10a0297e1fb04013c9050..f894d2c4271c3de3ff69082d9c4fcc9a6c6b3576 100644 (file)
--- a/ucw/lib.h
+++ b/ucw/lib.h
@@ -149,6 +149,20 @@ void assert_failed_noinfo(void) NONRET;
 #define DBG(x,y...) do { } while(0)
 #endif
 
+#ifdef DEBUG_ASSERTS
+/**
+ * Sometimes, we may want to check that a pointer points to a valid memory
+ * location before we start using it for anything more complicated. This
+ * macro checks pointer validity by reading the byte it points to.
+ **/
+#define ASSERT_READABLE(ptr) ({ volatile char *__p = (ptr); *__p; })
+/** Like the previous macro, but it checks writeability, too. **/
+#define ASSERT_WRITEABLE(ptr) ({ volatile char *__p = (ptr); *__p = *__p; })
+#else
+#define ASSERT_READABLE(ptr) do { } while(0)
+#define ASSERT_WRITEABLE(ptr) do { } while(0)
+#endif
+
 /*** === Memory allocation ***/
 
 /*