From ebe4796f6c0408713dc85c7752ae74cb9473d680 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Sep 2021 21:23:23 +0200 Subject: [PATCH] Remove unnecessary casts to wxWindow when using wxTopLevelWindows This list uses wxWindowBase for its elements, so downcasts are unnecessary and actually harmful as the downcast performed in the dtor results in undefined behaviour because the object is not a wxWindow any more by then (thanks to UBSAN for detecting this). --- src/common/wincmn.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 880b0c1922..a0a775ed0b 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -389,7 +389,7 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, // does not as the user should be able to resize the window) // // note that we can't use IsTopLevel() from ctor - if ( size != wxDefaultSize && !wxTopLevelWindows.Find((wxWindow *)this) ) + if ( size != wxDefaultSize && !wxTopLevelWindows.Find(this) ) SetMinSize(size); SetName(name); @@ -458,7 +458,7 @@ wxWindowBase::~wxWindowBase() // Just in case we've loaded a top-level window via LoadNativeDialog but // we weren't a dialog class - wxTopLevelWindows.DeleteObject((wxWindow*)this); + wxTopLevelWindows.DeleteObject(this); // Any additional event handlers should be popped before the window is // deleted as otherwise the last handler will be left with a dangling @@ -1383,7 +1383,7 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent) } else { - wxTopLevelWindows.DeleteObject((wxWindow *)this); + wxTopLevelWindows.DeleteObject(this); } // add it to the new one @@ -1393,7 +1393,7 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent) } else { - wxTopLevelWindows.Append((wxWindow *)this); + wxTopLevelWindows.Append(this); } // We need to notify window (and its subwindows) if by changing the parent