Skip to content

Commit

Permalink
Fix failed assertion "value >= 0" in o3tl::make_unsigned
Browse files Browse the repository at this point in the history
...after b294590 "Avoid explicit casts to
smaller sal_uInt16 from larger long":  As Mike Kaganski reported at
<https://gerrit.libreoffice.org/c/core/+/87442/2#
message-bc3d33b177eecba4255e299ac92c2f0c1712b57d>, clicking on "Templates" in
the start center causes the assert to fire at

> #3  0x00007ffff6296a66 in __GI___assert_fail
> #4  0x00007fffe6b11df8 in _ZN4o3tl13make_unsignedIlEENSt9enable_ifIXsr3stdE11is_signed_vIT_EENSt13make_unsignedIS2_E4typeEE4typeES2_ (value=-1) at include/o3tl/safeint.hxx:233
> #5  0x00007fffe6ad75f6 in ThumbnailView::SelectItem(unsigned short) (this=0x61a0000fc680, nItemId=1) at sfx2/source/control/thumbnailview.cxx:1011
> #6  0x00007fffe6ade62c in ThumbnailView::GetFocus() (this=0x61a0000fc680) at sfx2/source/control/thumbnailview.cxx:838
> #7  0x00007fffc27c292b in vcl::Window::CompatGetFocus() (this=0x61a0000fc680) at vcl/source/window/window.cxx:3895
> #8  0x00007fffc226604e in vcl::Window::ImplGrabFocus(GetFocusFlags) (this=0x61a0000fc680, nFlags=GetFocusFlags::NONE) at vcl/source/window/mouse.cxx:378
> #9  0x00007fffc2738071 in vcl::Window::GrabFocus() (this=0x61a0000fc680) at vcl/source/window/window.cxx:3029
> #10 0x00007fffe6c4a529 in BackingWindow::ClickHdl(Button*) (this=0x6190005e8880, pButton=0x61800031a080) at sfx2/source/dialog/backingwindow.cxx:585
> #11 0x00007fffe6c3c1eb in BackingWindow::LinkStubClickHdl(void*, Button*) (instance=0x6190005e8880, data=0x61800031a080) at sfx2/source/dialog/backingwindow.cxx:535
> #12 0x00007fffc2937f72 in Link<Button*, void>::Call(Button*) const (this=0x61800031a328, data=0x61800031a080) at include/tools/link.hxx:111
> #13 0x00007fffc291c13c in Button::Click()::$_0::operator()() const (this=0x7fff8c0ce0a0) at vcl/source/control/button.cxx:123

when mnFirstLine and mnVisLines are both 0.  (And nNewLine is 0 because nItemPos
is 0.  An alternative fix might be to replace

  else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )

with

  else if ( nNewLine >= o3tl::make_unsigned(mnFirstLine+mnVisLines) )

but that would then set

      mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1);

to 1 instead of leaving it at 0, which is probably not wanted.)

Change-Id: I5b61cd25d52048e2cb2cf64f646d8ba9dd10adb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88847
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
  • Loading branch information
stbergmann committed Feb 17, 2020
1 parent 502d7cc commit 28d844a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sfx2/source/control/thumbnailview.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ void ThumbnailView::SelectItem( sal_uInt16 nItemId )
{
mnFirstLine = nNewLine;
}
else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
else if ( mnVisLines != 0 && nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
{
mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1);
}
Expand Down Expand Up @@ -2176,7 +2176,7 @@ void SfxThumbnailView::SelectItem( sal_uInt16 nItemId )
{
mnFirstLine = nNewLine;
}
else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
else if ( mnVisLines != 0 && nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
{
mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1);
}
Expand Down

0 comments on commit 28d844a

Please sign in to comment.