diff -ruN qtbase-opensource-src-5.7.1-orig/src/gui/painting/qfixed_p.h qtbase-opensource-src-5.7.1/src/gui/painting/qfixed_p.h --- qtbase-opensource-src-5.7.1-orig/src/gui/painting/qfixed_p.h 2016-12-01 02:17:04.000000000 -0600 +++ qtbase-opensource-src-5.7.1/src/gui/painting/qfixed_p.h 2023-06-04 10:03:49.000000000 -0500 @@ -53,6 +53,7 @@ #include "QtCore/qdebug.h" #include "QtCore/qpoint.h" +#include #include "QtCore/qsize.h" QT_BEGIN_NAMESPACE @@ -181,6 +182,14 @@ Q_DECL_CONSTEXPR inline bool operator>(const QFixed &f, int i) { return f.value() > i * 64; } Q_DECL_CONSTEXPR inline bool operator>(int i, const QFixed &f) { return i * 64 > f.value(); } +inline bool qAddOverflow(QFixed v1, QFixed v2, QFixed *r) +{ + int val; + bool result = add_overflow(v1.value(), v2.value(), &val); + r->setValue(val); + return result; +} + #ifndef QT_NO_DEBUG_STREAM inline QDebug &operator<<(QDebug &dbg, const QFixed &f) { return dbg << f.toReal(); } diff -ruN qtbase-opensource-src-5.7.1-orig/src/gui/text/qtextlayout.cpp qtbase-opensource-src-5.7.1/src/gui/text/qtextlayout.cpp --- qtbase-opensource-src-5.7.1-orig/src/gui/text/qtextlayout.cpp 2016-12-01 02:17:04.000000000 -0600 +++ qtbase-opensource-src-5.7.1/src/gui/text/qtextlayout.cpp 2023-06-04 10:06:20.000000000 -0500 @@ -2036,11 +2036,14 @@ eng->maxWidth = qMax(eng->maxWidth, line.textWidth); } else { eng->minWidth = qMax(eng->minWidth, lbh.minw); - eng->maxWidth += line.textWidth; + if (qAddOverflow(eng->maxWidth, line.textWidth, &eng->maxWidth)) + eng->maxWidth = QFIXED_MAX; } - if (line.textWidth > 0 && item < eng->layoutData->items.size()) - eng->maxWidth += lbh.spaceData.textWidth; + if (line.textWidth > 0 && item < eng->layoutData->items.size()) { + if (qAddOverflow(eng->maxWidth, lbh.spaceData.textWidth, &eng->maxWidth)) + eng->maxWidth = QFIXED_MAX; + } if (eng->option.flags() & QTextOption::IncludeTrailingSpaces) line.textWidth += lbh.spaceData.textWidth; if (lbh.spaceData.length) {