Fix specific overflow in qtextlayout

Adds qAddOverflow and qMulOverflow definitions to QFixed

Fixes: QTBUG-113337
Pick-to: 6.5 6.5.1 6.2 5.15
Change-Id: I13579306defceaccdc0fbb1ec0e9b77c6f8d1af9
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Allan Sandfeld Jensen 2023-05-05 09:51:32 +02:00
parent 1b736a815b
commit 7b7a01c266
2 changed files with 23 additions and 3 deletions

View File

@ -18,6 +18,7 @@
#include <QtGui/private/qtguiglobal_p.h>
#include "QtCore/qdebug.h"
#include "QtCore/qpoint.h"
#include "QtCore/qnumeric.h"
#include "QtCore/qsize.h"
QT_BEGIN_NAMESPACE
@ -136,6 +137,22 @@ constexpr inline QFixed operator+(uint i, QFixed d) { return d+i; }
constexpr inline QFixed operator-(uint i, QFixed d) { return -(d-i); }
// constexpr inline QFixed operator*(qreal d, QFixed d2) { return d2*d; }
inline bool qAddOverflow(QFixed v1, QFixed v2, QFixed *r)
{
int val;
bool result = qAddOverflow(v1.value(), v2.value(), &val);
r->setValue(val);
return result;
}
inline bool qMulOverflow(QFixed v1, QFixed v2, QFixed *r)
{
int val;
bool result = qMulOverflow(v1.value(), v2.value(), &val);
r->setValue(val);
return result;
}
#ifndef QT_NO_DEBUG_STREAM
inline QDebug &operator<<(QDebug &dbg, QFixed f)
{ return dbg << f.toReal(); }

View File

@ -2164,9 +2164,12 @@ found:
eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
} else {
eng->minWidth = qMax(eng->minWidth, lbh.minw);
eng->layoutData->currentMaxWidth += line.textWidth;
if (!manuallyWrapped)
eng->layoutData->currentMaxWidth += lbh.spaceData.textWidth;
if (qAddOverflow(eng->layoutData->currentMaxWidth, line.textWidth, &eng->layoutData->currentMaxWidth))
eng->layoutData->currentMaxWidth = QFIXED_MAX;
if (!manuallyWrapped) {
if (qAddOverflow(eng->layoutData->currentMaxWidth, lbh.spaceData.textWidth, &eng->layoutData->currentMaxWidth))
eng->layoutData->currentMaxWidth = QFIXED_MAX;
}
eng->maxWidth = qMax(eng->maxWidth, eng->layoutData->currentMaxWidth);
if (manuallyWrapped)
eng->layoutData->currentMaxWidth = 0;