svtools/source/brwbox/brwbox1.cxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
New commits: commit 87270edb1b19e8553c8f7bc64e269d49f7262c27 Author: Neil Roberts <[email protected]> AuthorDate: Fri Oct 31 11:07:10 2025 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Sat Nov 1 08:10:34 2025 +0100 BrowseBox: Don’t set last column width to LONG_MAX when win is invisible BrowseBox::AutoSizeLastColumn calls SetColumnWidth with the width set to LONG_MAX. SetColumnWidth then tries to limit the actual width to the remaining space for the last column. However, this was only done when the window is visible, presumably because the remaining space calculations might not work otherwise. This width is later used to calculate a rectangle starting from the column’s X position. This of course ends up overflowing the Long variable so it could be counted as undefined behaviour. Instead, let’s just bail out early from the function when the window isn’t visible and leave the width as it was. The actual width will be recalculated when the window becomes visible anyway because Window::Show calls Resize. This was picked up by Stephan Bergmann with UBSAN and it was discussed in the comments for this patch: https://gerrit.libreoffice.org/c/core/+/193174 Change-Id: Ic2922a3d98c8ebc2e7f2d04c8c59105fdbd4e666 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193268 Reviewed-by: Stephan Bergmann <[email protected]> Tested-by: Jenkins diff --git a/svtools/source/brwbox/brwbox1.cxx b/svtools/source/brwbox/brwbox1.cxx index bec632584951..b19b8566c96d 100644 --- a/svtools/source/brwbox/brwbox1.cxx +++ b/svtools/source/brwbox/brwbox1.cxx @@ -593,15 +593,26 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, tools::Long nWidth ) tools::Long nOldWidth = mvCols[ nItemPos ]->Width(); // adjust last column, if necessary - if ( IsVisible() && nItemPos == mvCols.size() - 1 ) + if ( nItemPos == mvCols.size() - 1 ) { - tools::Long nMaxWidth = pDataWin->GetSizePixel().Width(); - nMaxWidth -= pDataWin->bAutoSizeLastCol + if ( IsVisible() ) + { + tools::Long nMaxWidth = pDataWin->GetSizePixel().Width(); + nMaxWidth -= pDataWin->bAutoSizeLastCol ? GetFieldRect(nItemId).Left() : GetFrozenWidth(); - if ( pDataWin->bAutoSizeLastCol || nWidth > nMaxWidth ) + if ( pDataWin->bAutoSizeLastCol || nWidth > nMaxWidth ) + { + nWidth = nMaxWidth > 16 ? nMaxWidth : nOldWidth; + } + } + else if ( nWidth == LONG_MAX ) { - nWidth = nMaxWidth > 16 ? nMaxWidth : nOldWidth; + // If we can’t calculate the maximum width because the window isn’t visible then it’s + // better to leave the width as it is than to set it to LONG_MAX. The last column width + // will be recalculated when the window is shown anyway because the window will be + // resized. + return; } }
