From 69cdec0eb3eff9fcafaacb4b06e43519dfe3a1fb Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 18 Feb 2012 13:08:07 +0100 Subject: [PATCH] lib.h: Added ASSERT_READABLE and ASSERT_WRITEABLE --- ucw/lib.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ucw/lib.h b/ucw/lib.h index f1ea7e9d..f894d2c4 100644 --- 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 ***/ /* -- 2.39.2