regedit: [1/2] Do not pass a global avaiable pointer to a static function

Detlef Riekenberg wine.dev at web.de
Wed Feb 7 17:08:44 CST 2007


 global: ChildWnd* g_pChildWnd;
 local: ChildWnd* pChildWnd = g_pChildWnd

We use a local copy of a global pointer and pass the local copy as
parameter to a static function.
This hide bugs in ChildWndProc:
During WM_DESTROY, the struct is freed and the local copy of the pointer
is cleared, but when the next message arrived, we create again a
local copy from the global pointer and access freed memory.
I needed to add the missing NULL-Check in WM_NOTIFY.



The first patch changes "ResizeWnd" to use the global pointer
The second Patch remove all local copies of the global Pointer
and add the missing NULL-Check for WM_NOTIFY


Changelog:
regedit: Do not pass a global available pointer to a static function:
         use the global direct



-- 
 
By by ... Detlef

-------------- next part --------------
>From 98fdbf586599a798a3427a6cfecdb63c6678c321 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Wed, 7 Feb 2007 21:48:17 +0100
Subject: [PATCH] regedit: do not pass a global pointer to a static function (use the global direct)
---
 programs/regedit/childwnd.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c
index b7262ff..3b3be61 100644
--- a/programs/regedit/childwnd.c
+++ b/programs/regedit/childwnd.c
@@ -60,14 +60,14 @@ static void draw_splitbar(HWND hWnd, int
     ReleaseDC(hWnd, hdc);
 }
 
-static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
+static void ResizeWnd(int cx, int cy)
 {
     HDWP hdwp = BeginDeferWindowPos(2);
     RECT rt = {0, 0, cx, cy};
 
-    cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
-    DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
-    DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx  , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
+    cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH/2;
+    DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, 0, rt.left, rt.top, g_pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
+    DeferWindowPos(hdwp, g_pChildWnd->hListWnd, 0, rt.left+cx  , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
     EndDeferWindowPos(hdwp);
 }
 
@@ -263,7 +263,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd,
             last_split = -1;
             GetClientRect(hWnd, &rt);
             pChildWnd->nSplitPos = x;
-            ResizeWnd(pChildWnd, rt.right, rt.bottom);
+            ResizeWnd(rt.right, rt.bottom);
             ReleaseCapture();
         }
         break;
@@ -279,7 +279,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd,
                 RECT rt;
                 draw_splitbar(hWnd, last_split);
                 GetClientRect(hWnd, &rt);
-                ResizeWnd(pChildWnd, rt.right, rt.bottom);
+                ResizeWnd(rt.right, rt.bottom);
                 last_split = -1;
                 ReleaseCapture();
                 SetCursor(LoadCursor(0, IDC_ARROW));
@@ -364,7 +364,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd,
 
     case WM_SIZE:
         if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
-            ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
+            ResizeWnd(LOWORD(lParam), HIWORD(lParam));
         }
         /* fall through */
 default: def:
-- 
1.4.1



More information about the wine-patches mailing list