diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-08-18 07:11:12 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-08-18 07:11:12 (GMT) |
commit | fb4a884eb76a67919112f2a389283b1bd6d4848e (patch) | |
tree | 387d56c651cdf629325afe48ef00f27e1c72cd88 /src | |
parent | 572e165dcb8cc8fcdfaa4ab9bdab050f6a6cc173 (diff) | |
download | Qt-fb4a884eb76a67919112f2a389283b1bd6d4848e.zip Qt-fb4a884eb76a67919112f2a389283b1bd6d4848e.tar.gz Qt-fb4a884eb76a67919112f2a389283b1bd6d4848e.tar.bz2 |
Avoid divide by zero on buggy Xlib/Xserver implementations
Some X servers seem to report zero physical size, so our DPI
calculations would crash with divide-by-zero. Avoid this and just use
72 DPI instead.
Task-number: 258319
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qapplication_x11.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index db349f0..d942519 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -1851,10 +1851,20 @@ void qt_init(QApplicationPrivate *priv, int, QX11InfoData *screen = X11->screens + s; screen->ref = 1; // ensures it doesn't get deleted screen->screen = s; - screen->dpiX = (DisplayWidth(X11->display, s) * 254 + DisplayWidthMM(X11->display, s)*5) - / (DisplayWidthMM(X11->display, s)*10); - screen->dpiY = (DisplayHeight(X11->display, s) * 254 + DisplayHeightMM(X11->display, s)*5) - / (DisplayHeightMM(X11->display, s)*10); + + int widthMM = DisplayWidthMM(X11->display, s); + if (widthMM != 0) { + screen->dpiX = (DisplayWidth(X11->display, s) * 254 + widthMM * 5) / (widthMM * 10); + } else { + screen->dpiX = 72; + } + + int heightMM = DisplayHeightMM(X11->display, s); + if (heightMM != 0) { + screen->dpiY = (DisplayHeight(X11->display, s) * 254 + heightMM * 5) / (heightMM * 10); + } else { + screen->dpiY = 72; + } X11->argbVisuals[s] = 0; X11->argbColormaps[s] = 0; |