From: Martin Mares Date: Sat, 18 Feb 2012 12:08:07 +0000 (+0100) Subject: lib.h: Added ASSERT_READABLE and ASSERT_WRITEABLE X-Git-Tag: v5.0~33 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=69cdec0eb3eff9fcafaacb4b06e43519dfe3a1fb;p=libucw.git lib.h: Added ASSERT_READABLE and ASSERT_WRITEABLE --- 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 ***/ /*