From: Paul Durrant Date: Mon, 6 Sep 2021 08:43:46 +0000 (+0100) Subject: Fix semantics of ASSERT3[P|S|U] X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=40e212777f2620ea0aee55bad10bcf6afed39baf;p=pvdrivers%2Fwin%2Fxenvif.git Fix semantics of ASSERT3[P|S|U] These ASSERTions are supposed to cast their arguments to pointer, signed or unsigned values (respectively) before applying the operator. This is not done correctly; the test and __analysis_assume() directive in the underlying ASSERT() macro are applied to the un-cast values. This patch rectifies the situation. Signed-off-by: Paul Durrant --- diff --git a/src/xenvif/assert.h b/src/xenvif/assert.h index 110f4ef..dade311 100644 --- a/src/xenvif/assert.h +++ b/src/xenvif/assert.h @@ -76,19 +76,17 @@ __Bug( #if DBG -#define __NT_ASSERT(_EXP) \ - ((!(_EXP)) ? \ +#define __ASSERT_FAIL(_EXP) \ (Error("ASSERTION FAILED: " #_EXP "\n"), \ __annotation(L"Debug", L"AssertFail", L#_EXP), \ - DbgRaiseAssertionFailure(), FALSE) : \ - TRUE) - -#define __ASSERT(_EXP) __NT_ASSERT(_EXP) - -#define ASSERT(_EXP) \ - do { \ - __ASSERT(_EXP); \ - __analysis_assume(_EXP); \ + DbgRaiseAssertionFailure()) + +#define ASSERT(_EXP) \ + do { \ + if (!(_EXP)) { \ + __ASSERT_FAIL(_EXP); \ + __analysis_assume(_EXP); \ + } \ } while (FALSE) #define ASSERT3U(_X, _OP, _Y) \ @@ -98,7 +96,8 @@ __Bug( if (!(_Lval _OP _Rval)) { \ Error("%s = %llu\n", #_X, _Lval); \ Error("%s = %llu\n", #_Y, _Rval); \ - ASSERT((_X) _OP (_Y)); \ + __ASSERT_FAIL(_X _OP _Y); \ + __analysis_assume(_Lval _OP _Rval); \ } \ } while (FALSE) @@ -109,7 +108,8 @@ __Bug( if (!(_Lval _OP _Rval)) { \ Error("%s = %lld\n", #_X, _Lval); \ Error("%s = %lld\n", #_Y, _Rval); \ - ASSERT((_X) _OP (_Y)); \ + __ASSERT_FAIL(_X _OP _Y); \ + __analysis_assume(_Lval _OP _Rval); \ } \ } while (FALSE) @@ -120,7 +120,8 @@ __Bug( if (!(_Lval _OP _Rval)) { \ Error("%s = %p\n", #_X, _Lval); \ Error("%s = %p\n", #_Y, _Rval); \ - ASSERT((_X) _OP (_Y)); \ + __ASSERT_FAIL(_X _OP _Y); \ + __analysis_assume(_Lval _OP _Rval); \ } \ } while (FALSE) @@ -134,14 +135,29 @@ __Bug( __analysis_assume(_EXP); \ } while (FALSE) -#define ASSERT3U(_X, _OP, _Y) \ - ASSERT((_X) _OP (_Y)) +#define ASSERT3U(_X, _OP, _Y) \ + do { \ + ULONGLONG _Lval = (ULONGLONG)(_X); \ + ULONGLONG _Rval = (ULONGLONG)(_Y); \ + \ + __analysis_assume(_Lval _OP _Rval); \ + } while (FALSE) -#define ASSERT3S(_X, _OP, _Y) \ - ASSERT((_X) _OP (_Y)) +#define ASSERT3S(_X, _OP, _Y) \ + do { \ + LONGLONG _Lval = (LONGLONG)(_X); \ + LONGLONG _Rval = (LONGLONG)(_Y); \ + \ + __analysis_assume(_Lval _OP _Rval); \ + } while (FALSE) -#define ASSERT3P(_X, _OP, _Y) \ - ASSERT((_X) _OP (_Y)) +#define ASSERT3P(_X, _OP, _Y) \ + do { \ + PVOID _Lval = (PVOID)(_X); \ + PVOID _Rval = (PVOID)(_Y); \ + \ + __analysis_assume(_Lval _OP _Rval); \ + } while (FALSE) #endif // DBG