[PATCH] kernel32/tests: Use a volatile pointer to cause a crash in the debugger tests. (Clang)

Charles Davis cdavis5x at gmail.com
Tue Sep 22 17:12:05 CDT 2015


Dereferencing a null pointer is undefined behavior according to the C
standard. If Clang can prove that a pointer dereference will always be
null, it will replace it with a 'ud2' instruction. This still triggers a
crash, but with the wrong exception (STATUS_INVALID_OPCODE instead of
STATUS_ACCESS_VIOLATION). Making the pointer volatile inhibits this
optimization, causing the program to die with the correct exception.

Signed-off-by: Charles Davis <cdavis5x at gmail.com>
---
 dlls/kernel32/tests/debugger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dlls/kernel32/tests/debugger.c b/dlls/kernel32/tests/debugger.c
index a802784..326a903 100644
--- a/dlls/kernel32/tests/debugger.c
+++ b/dlls/kernel32/tests/debugger.c
@@ -158,7 +158,7 @@ typedef struct
 
 static void doCrash(int argc,  char** argv)
 {
-    char* p;
+    volatile char* p;
 
     /* make sure the exception gets to the debugger */
     SetErrorMode( 0 );
-- 
2.5.3




More information about the wine-patches mailing list