diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp index e832d3683..4dfb8717f 100644 --- a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp @@ -1341,14 +1341,16 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) SelfIndex=FindGrid(GetMenu(hWnd)); - //update the grid width and height variable + // the following check will prevent memory overwriting bug by BabyGrid during the WM_NCCREATE, WM_NCCALCSIZE, WM_CREATE and WM_NCDESTROY + // - TODO: if the above FindGrid can theoretically return -1, the whole BabyGrid code here is theoretically flawed and needs a review + // (luckily it seems it never returns -1 apart from the aforementioned 4 WMs above) + if (SelfIndex != -1) { - RECT rect; - - GetClientRect(hWnd,&rect); - BGHS[SelfIndex].gridwidth = rect.right - rect.left; - BGHS[SelfIndex].gridheight = rect.bottom - rect.top; - + // update the grid width and height variable + RECT rect{}; + ::GetClientRect(hWnd, &rect); + BGHS[SelfIndex].gridwidth = rect.right - rect.left; + BGHS[SelfIndex].gridheight = rect.bottom - rect.top; } ReturnValue = 0;