Fix divide by zero when opening font on invalid image

If you open a QFont on an invalid image, its dpi will be 0. In
other places we check for this before calculating the point
size, but this was missing in one spot, causing divide by
zero.

This would happen e.g. in the tst_QFontMetrics::same() test.
While it would pass normally, running this with an undefined sanitizer build would warn about the division by zero.

There's nothing useful we can do with the fonts on the invalid
image, so like in the other places, we just leave the point size
as is when this happens.

Pick-to: 6.8 6.5 5.15
Change-Id: I4769e23e2b4dbb92f675cb8a77f8554c90bc2afd
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
(cherry picked from commit c136de2deb46fb5f60728bc5a4083b9439ea0a3a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2025-02-07 10:29:18 +01:00 committed by Qt Cherry-pick Bot
parent c1bb08ab26
commit 333a08c98f

View File

@ -2828,7 +2828,8 @@ void QFontDatabasePrivate::load(const QFontPrivate *d, int script)
req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100;
req.pixelSize = qRound(req.pixelSize);
}
if (req.pointSize < 0)
if (req.pointSize < 0 && d->dpi > 0)
req.pointSize = req.pixelSize*72.0/d->dpi;
// respect the fallback families that might be passed through the request