From 9f5f8d13c56a2db60ce578817cbc385f984f61e7 Mon Sep 17 00:00:00 2001 From: milipili Date: Sat, 30 May 2015 23:34:58 +0200 Subject: [PATCH] documentmap: ViewZoneDlg: fixed uninitialized variables The real problem is `_viewZoneCanvas`, which can be used unitialized by `drawZone`. --- .../src/WinControls/DocumentMap/documentMap.cpp | 14 +++++++++----- .../src/WinControls/DocumentMap/documentMap.h | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index e584a4ab3..11f50af03 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -440,9 +440,13 @@ BOOL CALLBACK ViewZoneDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara case WM_INITDIALOG : { _viewZoneCanvas = ::GetDlgItem(_hSelf, IDC_VIEWZONECANVAS); - ::SetWindowLongPtrW(_viewZoneCanvas, GWL_USERDATA, reinterpret_cast(this)); - _canvasDefaultProc = reinterpret_cast(::SetWindowLongPtr(_viewZoneCanvas, GWL_WNDPROC, reinterpret_cast(canvasStaticProc))); - return TRUE; + if (NULL != _viewZoneCanvas) + { + ::SetWindowLongPtrW(_viewZoneCanvas, GWL_USERDATA, reinterpret_cast(this)); + _canvasDefaultProc = reinterpret_cast(::SetWindowLongPtr(_viewZoneCanvas, GWL_WNDPROC, reinterpret_cast(canvasStaticProc))); + return TRUE; + } + break; } case WM_LBUTTONDOWN: @@ -466,7 +470,7 @@ BOOL CALLBACK ViewZoneDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara case WM_SIZE: { - if (_viewZoneCanvas) + if (NULL != _viewZoneCanvas) { int width = LOWORD(lParam); int height = HIWORD(lParam); @@ -479,8 +483,8 @@ BOOL CALLBACK ViewZoneDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara { //Have to perform the scroll first, because the first/last line do not get updated untill after the scroll has been parsed ::SendMessage(_hParent, DOCUMENTMAP_MOUSEWHEEL, wParam, lParam); + return TRUE; } - return TRUE; case WM_DESTROY : { diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.h b/PowerEditor/src/WinControls/DocumentMap/documentMap.h index de688eca6..27b86e29a 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.h +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.h @@ -53,7 +53,7 @@ enum moveMode { class ViewZoneDlg : public StaticDialog { public : - ViewZoneDlg() : StaticDialog() {}; + ViewZoneDlg() : StaticDialog(), _viewZoneCanvas(NULL), _canvasDefaultProc(nullptr), _higherY(0), _lowerY(0) {} void doDialog(); @@ -63,7 +63,8 @@ public : void drawZone(long hY, long lY) { _higherY = hY; _lowerY = lY; - ::InvalidateRect(_viewZoneCanvas, NULL, TRUE); + if (NULL != _viewZoneCanvas) + ::InvalidateRect(_viewZoneCanvas, NULL, TRUE); }; int getViewerHeight() const {