From 4ca43c71eb4f1b2cb969a219e3f1d3b12af02309 Mon Sep 17 00:00:00 2001 From: Mike Kuta Date: Fri, 6 Feb 2015 11:34:28 -0500 Subject: Improved Windows printer support and fixed crashes due to NULL devMode With certain printer drivers, the PRINTER_INFO_2 can return NULL for the pDevMode member in the call to GetPrinter() as mentioned on MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd144911 In many places, Qt first checks that devMode isn't NULL before dereferencing it. In other places it does not (such as when it actually attempts to print in QWin32PrintEngine::begin()). Checking every dereference aside, most printer functionality is removed without access to the DEVMODE structure. This fix uses DocumentProperties() to get the DEVMODE information when the first method fails. [ChangeLog][QtPrintSupport][QPrinter][Windows] Improved Windows printer support and fixed crashes due to NULL devMode Task-number: QTBUG-44349 Task-number: QTBUG-43877 Task-number: QTBUG-2251 Change-Id: Iafa337055d967c70f2096dcde4cc9c8ca8a0d252 Reviewed-by: Andy Shaw --- src/printsupport/dialogs/qpagesetupdialog_win.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/printsupport/dialogs/qpagesetupdialog_win.cpp') diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp index 9185705bcf..baa8f93454 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp +++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp @@ -134,6 +134,13 @@ int QPageSetupDialog::exec() // copy from our temp DEVMODE struct if (!engine->globalDevMode() && hDevMode) { + // Make sure memory is allocated + if (ep->ownsDevMode && ep->devMode) + free(ep->devMode); + ep->devMode = (DEVMODE *) malloc(devModeSize); + ep->ownsDevMode = true; + + // Copy void *src = GlobalLock(hDevMode); memcpy(ep->devMode, src, devModeSize); GlobalUnlock(hDevMode); -- cgit v1.2.3