summaryrefslogtreecommitdiffstats
path: root/src/printsupport/dialogs
diff options
context:
space:
mode:
authorMike Kuta <mike@kutasoftware.com>2015-02-06 11:34:28 -0500
committerAndy Shaw <andy.shaw@digia.com>2015-03-06 08:23:13 +0000
commit4ca43c71eb4f1b2cb969a219e3f1d3b12af02309 (patch)
tree7a204560fb6ab13dde7661c1d8ee3b7a58a879e3 /src/printsupport/dialogs
parent208cd9ebf16afd2b7a5b08d62ac2647b99a3f612 (diff)
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 <andy.shaw@digia.com>
Diffstat (limited to 'src/printsupport/dialogs')
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_win.cpp7
1 files changed, 7 insertions, 0 deletions
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);