]> xenbits.xensource.com Git - pvdrivers/win/xenvif.git/commitdiff
Fix semantics of ASSERT3[P|S|U]
authorPaul Durrant <pdurrant@amazon.com>
Mon, 6 Sep 2021 08:43:46 +0000 (09:43 +0100)
committerPaul Durrant <pdurrant@amazon.com>
Mon, 6 Sep 2021 11:52:48 +0000 (12:52 +0100)
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 <pdurrant@amazon.com>
src/xenvif/assert.h

index 110f4ef726f5122b2a7fffa92bd4311c0e65266f..dade311c23ead2e997a2c1c70e15ebd1ceacd299 100644 (file)
@@ -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