diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 04727f2a511..90fbf3e1aa3 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -27,6 +27,7 @@ #include #include +#include #ifndef QT_NO_DATASTREAM #include #endif @@ -415,7 +416,8 @@ void QHeaderView::setOffset(int newOffset) Q_D(QHeaderView); if (d->headerOffset == newOffset) return; - int ndelta = d->headerOffset - newOffset; + // don't overflow; this function is checked with both INT_MIN and INT_MAX... + const int ndelta = qt_saturate(d->headerOffset - qint64{newOffset}); d->headerOffset = newOffset; if (d->orientation == Qt::Horizontal) d->viewport->scroll(isRightToLeft() ? -ndelta : ndelta, 0);