From 154b3897244118f08e2a3d23646442b131a2a2a4 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sat, 16 Nov 2013 15:00:11 +0000 Subject: [PATCH] [DDK][XDK] - Do not evaluate the ASSERT macro's parameter before stringifying it CORE-7588 #resolve svn path=/trunk/; revision=61008 --- reactos/include/ddk/wdm.h | 23 ++++++++++++++++++----- reactos/include/xdk/rtlfuncs.h | 23 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/reactos/include/ddk/wdm.h b/reactos/include/ddk/wdm.h index b7c9a63a563..c926375f0b5 100644 --- a/reactos/include/ddk/wdm.h +++ b/reactos/include/ddk/wdm.h @@ -11010,14 +11010,27 @@ RtlCheckBit( DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE) #define RTL_SOFT_VERIFYMSG(msg, exp) \ - (VOID)((!(exp)) ? \ + ((!(exp)) ? \ DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE) -#define ASSERT(exp) ((void)RTL_VERIFY(exp)) -#define ASSERTMSG(msg, exp) ((void)RTL_VERIFYMSG(msg, exp)) +/* The ASSERTs must be cast to void to avoid warnings about unused results. + * We also cannot invoke the VERIFY versions because the indirection messes + * with stringify. */ +#define ASSERT(exp) \ + ((VOID)((!(exp)) ? \ + RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)) -#define RTL_SOFT_ASSERT(exp) ((void)RTL_SOFT_VERIFY(exp)) -#define RTL_SOFT_ASSERTMSG(msg, exp) ((void)RTL_SOFT_VERIFYMSG(msg, exp)) +#define ASSERTMSG(msg, exp) \ + ((VOID)((!(exp)) ? \ + RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, (PCHAR)msg ), FALSE : TRUE)) + +#define RTL_SOFT_ASSERT(exp) \ + ((VOID)((!(exp)) ? \ + DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)) + +#define RTL_SOFT_ASSERTMSG(msg, exp) \ + ((VOID)((!(exp)) ? \ + DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE)) #if defined(_MSC_VER) # define __assert_annotationA(msg) __annotation(L"Debug", L"AssertFail", L ## msg) diff --git a/reactos/include/xdk/rtlfuncs.h b/reactos/include/xdk/rtlfuncs.h index d696f774949..4a47c7b8954 100644 --- a/reactos/include/xdk/rtlfuncs.h +++ b/reactos/include/xdk/rtlfuncs.h @@ -3076,14 +3076,27 @@ RtlCheckBit( DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE) #define RTL_SOFT_VERIFYMSG(msg, exp) \ - (VOID)((!(exp)) ? \ + ((!(exp)) ? \ DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE) -#define ASSERT(exp) ((void)RTL_VERIFY(exp)) -#define ASSERTMSG(msg, exp) ((void)RTL_VERIFYMSG(msg, exp)) +/* The ASSERTs must be cast to void to avoid warnings about unused results. + * We also cannot invoke the VERIFY versions because the indirection messes + * with stringify. */ +#define ASSERT(exp) \ + ((VOID)((!(exp)) ? \ + RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)) -#define RTL_SOFT_ASSERT(exp) ((void)RTL_SOFT_VERIFY(exp)) -#define RTL_SOFT_ASSERTMSG(msg, exp) ((void)RTL_SOFT_VERIFYMSG(msg, exp)) +#define ASSERTMSG(msg, exp) \ + ((VOID)((!(exp)) ? \ + RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, (PCHAR)msg ), FALSE : TRUE)) + +#define RTL_SOFT_ASSERT(exp) \ + ((VOID)((!(exp)) ? \ + DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)) + +#define RTL_SOFT_ASSERTMSG(msg, exp) \ + ((VOID)((!(exp)) ? \ + DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE)) #if defined(_MSC_VER) # define __assert_annotationA(msg) __annotation(L"Debug", L"AssertFail", L ## msg)