tdf#152532 vcl: Don't convert negative entry count to unsigned
In particular for empty output sizes (as is the case for
the observed cases from tdf#152532, where
`SvImpLBox::AdjustScrollBars` gets called before the
resize to the final size happens),
(aOSize.Height() - m_nHorSBarHeight) / nEntryHeight
can become negative, and that was silently converted
into a large positive integer when assigned to `m_nVisibleCount`
which is of type `sal_uLong`. As a result, `SvImpLBox::FillView`
later moved the view to the very top of the scroll area and did
not make sure that the selected entry would remain inside of the view.
Prevent that by using 0 as minimum value.
Also explicitly convert to unsigned using `o3tl::make_unsigned`
at another place that should be fine (but will trigger an assert
now if it isn't, rather than silently converting a negative
value to unsigned).
Change-Id: Iab1402603adb7b7c93927ecbfd10336049bfd71b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144744
Tested-by: Jenkins
Reviewed-by: Rafael Lima <rafael.palma.lima@gmail.com>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
(cherry picked from commit 2d0ff08f8724c6fd2b7801c7eb8fa0a41a90f883)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144727
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/vcl/source/treelist/svimpbox.cxx b/vcl/source/treelist/svimpbox.cxx
index b5efa69..af9d2b1 100644
--- a/vcl/source/treelist/svimpbox.cxx
+++ b/vcl/source/treelist/svimpbox.cxx
@@ -1132,7 +1132,7 @@ void SvImpLBox::AdjustScrollBars( Size& rSize )
sal_uLong nTotalCount = m_pView->GetVisibleCount();
// number of entries visible within the view
m_nVisibleCount = aOSize.Height() / nEntryHeight;
m_nVisibleCount = o3tl::make_unsigned(aOSize.Height() / nEntryHeight);
// do we need a vertical scrollbar?
if( bVerSBar || nTotalCount > m_nVisibleCount )
@@ -1153,7 +1153,7 @@ void SvImpLBox::AdjustScrollBars( Size& rSize )
nResult |= 0x0002;
// the number of entries visible within the view has to be recalculated
// because the horizontal scrollbar is now visible.
m_nVisibleCount = (aOSize.Height() - m_nHorSBarHeight) / nEntryHeight;
m_nVisibleCount = o3tl::make_unsigned(std::max<tools::Long>(0, aOSize.Height() - m_nHorSBarHeight) / nEntryHeight);
// we might actually need a vertical scrollbar now
if( !(nResult & 0x0001) &&
((nTotalCount > m_nVisibleCount) || bVerSBar) )