[3/3] WineD3D: Avoid a NULL pointer dereference in UpdateTexture (Coverity)

Stefan Dösinger stefan at codeweavers.com
Thu Jan 11 17:20:42 CST 2007


pSourceRect may be NULL, so make sure not to dereference it without a check.

I decided not to send patch 3, so this one has number 4.
-------------- next part --------------
From 2420d2f0396c9199f26e5a8cab3a7b35ed535b58 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Fri, 12 Jan 2007 00:04:18 +0100
Subject: [PATCH] WineD3D: Avoid a null pointer dereference in UpdateTexture

---
 dlls/wined3d/device.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index e506685..eb1b2b1 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -5154,7 +5154,7 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
     unsigned int  srcSurfaceWidth, srcSurfaceHeight, destSurfaceWidth, destSurfaceHeight;
     WINED3DFORMAT destFormat, srcFormat;
     UINT          destSize;
-    int destLeft, destTop;
+    int srcLeft, destLeft, destTop;
     WINED3DPOOL       srcPool, destPool;
     int offset    = 0;
     int rowoffset = 0; /* how many bytes to add onto the end of a row to wraparound to the beginning of the next */
@@ -5204,15 +5204,16 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
     /* this needs to be done in lines if the sourceRect != the sourceWidth */
     srcWidth   = pSourceRect ? pSourceRect->right - pSourceRect->left   : srcSurfaceWidth;
     srcHeight  = pSourceRect ? pSourceRect->top   - pSourceRect->bottom : srcSurfaceHeight;
+    srcLeft    = pSourceRect ? pSourceRect->left : 0;
     destLeft   = pDestPoint  ? pDestPoint->x : 0;
     destTop    = pDestPoint  ? pDestPoint->y : 0;
 
 
     /* This function doesn't support compressed textures
     the pitch is just bytesPerPixel * width */
-    if(srcWidth != srcSurfaceWidth  || (pSourceRect != NULL && pSourceRect->left != 0) ){
+    if(srcWidth != srcSurfaceWidth  || srcLeft ){
         rowoffset = (srcSurfaceWidth - srcWidth) * pSrcSurface->bytesPerPixel;
-        offset   += pSourceRect->left * pSrcSurface->bytesPerPixel;
+        offset   += srcLeft * pSrcSurface->bytesPerPixel;
         /* TODO: do we ever get 3bpp?, would a shift and an add be quicker than a mul (well maybe a cycle or two) */
     }
     /* TODO DXT formats */
-- 
1.4.4.3



More information about the wine-patches mailing list