DXGL r489 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r488‎ | r489 | r490 >
Date:14:14, 16 August 2014
Author:admin
Status:new
Tags:
Comment:
Make memory pointer verification more robust against compiler optimizations.
Modified paths:
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/util.c (modified) (history)
  • /ddraw/util.h (modified) (history)

Diff [purge]

Index: ddraw/ddraw.cpp
@@ -303,7 +303,7 @@
304304 HRESULT WINAPI DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, LPVOID lpContext)
305305 {
306306 TRACE_ENTER(2,14,lpCallback,14,lpContext);
307 - if(IsBadReadPointer(lpCallback))
 307+ if(!IsReadablePointer(lpCallback))
308308 {
309309 TRACE_EXIT(23,DDERR_INVALIDPARAMS);
310310 return DDERR_INVALIDPARAMS;
@@ -341,7 +341,7 @@
342342 HRESULT WINAPI DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback, LPVOID lpContext)
343343 {
344344 TRACE_ENTER(2,14,lpCallback,14,lpContext);
345 - if(IsBadReadPointer(lpCallback))
 345+ if(!IsReadablePointer(lpCallback))
346346 {
347347 TRACE_EXIT(23,DDERR_INVALIDPARAMS);
348348 return DDERR_INVALIDPARAMS;
@@ -387,7 +387,7 @@
388388 HRESULT WINAPI DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
389389 {
390390 TRACE_ENTER(3,14,lpCallback,14,lpContext,9,dwFlags);
391 - if(IsBadReadPointer(lpCallback))
 391+ if(!IsReadablePointer(lpCallback))
392392 {
393393 TRACE_EXIT(23,DDERR_INVALIDPARAMS);
394394 return DDERR_INVALIDPARAMS;
@@ -448,7 +448,7 @@
449449 HRESULT WINAPI DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback, LPVOID lpContext, DWORD dwFlags)
450450 {
451451 TRACE_ENTER(3,14,lpCallback,14,lpContext,9,dwFlags);
452 - if(IsBadReadPointer(lpCallback))
 452+ if(!IsReadablePointer(lpCallback))
453453 {
454454 TRACE_EXIT(23,DDERR_GENERIC);
455455 return DDERR_INVALIDPARAMS;
Index: ddraw/glDirectDraw.cpp
@@ -573,7 +573,7 @@
574574 {
575575 TRACE_ENTER(3,14,this,24,lpGUID,14,pUnkOuter);
576576 initialized = false;
577 - if(((ULONG_PTR)lpGUID > 2) && IsBadReadPointer(lpGUID))
 577+ if(((ULONG_PTR)lpGUID > 2) && !IsReadablePointer(lpGUID))
578578 {
579579 error = DDERR_INVALIDPARAMS ;
580580 TRACE_EXIT(-1,0);
Index: ddraw/util.c
@@ -27,36 +27,23 @@
2828 * @return
2929 * Returns false if the pointer is valid, or true if an error occurs.
3030 */
31 -BOOL IsBadReadPointer(void *ptr)
 31+char IsReadablePointer(void *ptr)
3232 {
3333 char a;
34 - TRACE_ENTER(1, 14, ptr);
35 - if(!ptr)
36 - {
37 - TRACE_EXIT(22,1);
38 - return TRUE;
39 - }
 34+ if(!ptr) return 0;
4035 #ifdef _MSC_VER
4136 __try
4237 {
4338 a = *(char*)ptr;
44 - if(a == *(char*)ptr)
45 - {
46 - TRACE_EXIT(22,0);
47 - return FALSE;
48 - }
49 - else
50 - {
51 - TRACE_EXIT(22,1);
52 - return TRUE;
53 - }
 39+ if (!a) a++;
 40+ return a;
5441 }
5542 __except (GetExceptionCode() == STATUS_ACCESS_VIOLATION)
5643 {
57 - TRACE_EXIT(22,1);
58 - return TRUE;
 44+ return 0;
5945 }
6046 #else
61 - TRACE_RET(BOOL, 22, IsBadReadPtr(ptr, 1));
 47+ if(IsBadReadPtr(ptr,1) return 0;
 48+ else return 1;)
6249 #endif
6350 }
Index: ddraw/util.h
@@ -23,7 +23,7 @@
2424 extern "C" {
2525 #endif
2626
27 -BOOL IsBadReadPointer(void *ptr);
 27+char IsReadablePointer(void *ptr);
2828
2929 #ifdef __cplusplus
3030 }