From fb4a884eb76a67919112f2a389283b1bd6d4848e Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 18 Aug 2009 09:11:12 +0200 Subject: 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 --- src/gui/kernel/qapplication_x11.cpp | 18 ++++++++++++++---- 1 file 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; -- cgit v0.12