Ensure we don't crash when checking for cancelling print job

Don't dereference sm_abortWindow without checking that it is non-null in
wxAbortProc(): even though it's not supposed to happen, it still somehow
does, apparently, so just log a debug message instead of crashing in
this case.

See #23927.

(cherry picked from commit 9a728192c4340b34d2509898f7f16b767a794ac9)
This commit is contained in:
Vadim Zeitlin 2023-10-02 20:28:12 +02:00
parent 0efe1b7c29
commit 8de60c856f
2 changed files with 14 additions and 1 deletions

View File

@ -324,6 +324,7 @@ wxMSW:
- Fix wrong wxWindowsPrintNativeData initialization (Stefan Ziegler, #23685).
- Fix position of wxStaticBox label after DPI change (Maarten Bent, #23740).
- Fix background colour of empty cells in wxDataViewCtrl (#23708).
- Fix possible (even if rare) crash in printer progress dialog (#23927).
wxOSX:

View File

@ -425,12 +425,24 @@ BOOL CALLBACK wxAbortProc(HDC WXUNUSED(hdc), int WXUNUSED(error))
return(TRUE);
/* Process messages intended for the abort dialog box */
const HWND hwnd = GetHwndOf(wxPrinterBase::sm_abortWindow);
while (!wxPrinterBase::sm_abortIt && ::PeekMessage(&msg, 0, 0, 0, TRUE))
if (!IsDialogMessage((HWND) wxPrinterBase::sm_abortWindow->GetHWND(), &msg)) {
{
// Apparently handling the message may, somehow, result in
// sm_abortWindow being destroyed, so guard against this happening.
if (!wxPrinterBase::sm_abortWindow)
{
wxLogDebug(wxS("Print abort dialog unexpected disappeared."));
return TRUE;
}
if (!IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* bAbort is TRUE (return is FALSE) if the user has aborted */