From a7c772566bb8ac6a088b808cf0ef550e7b06560b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 18 Dec 2017 09:54:02 +0000 Subject: coverity#1426163 Improper use of negative value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit started life as sal_uIntPtr and the various checks are typically nPos < thing.size() just checking one bound, so sal_uInt32 looks safer after all Change-Id: Ibac839fc45b10d96ce4d4c8002fd26b20f70ae1c Reviewed-on: https://gerrit.libreoffice.org/46697 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- svx/source/gallery2/galbrws2.cxx | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'svx/source/gallery2/galbrws2.cxx') diff --git a/svx/source/gallery2/galbrws2.cxx b/svx/source/gallery2/galbrws2.cxx index a3c96fbb5095..ed027773324b 100644 --- a/svx/source/gallery2/galbrws2.cxx +++ b/svx/source/gallery2/galbrws2.cxx @@ -111,7 +111,7 @@ class GalleryThemePopup : public ::cppu::WeakImplHelper< css::frame::XStatusList { private: const GalleryTheme* mpTheme; - sal_uIntPtr mnObjectPos; + sal_uInt32 mnObjectPos; bool mbPreview; VclBuilder maBuilder; VclPtr mpPopupMenu; @@ -128,7 +128,7 @@ private: DECL_LINK( BackgroundMenuSelectHdl, Menu*, bool ); public: GalleryThemePopup( const GalleryTheme* pTheme, - sal_uIntPtr nObjectPos, + sal_uInt32 nObjectPos, bool bPreview, GalleryBrowser2* pBrowser ); @@ -141,7 +141,7 @@ public: GalleryThemePopup::GalleryThemePopup( const GalleryTheme* pTheme, - sal_uIntPtr nObjectPos, + sal_uInt32 nObjectPos, bool bPreview, GalleryBrowser2* pBrowser ) : mpTheme( pTheme ) @@ -559,8 +559,8 @@ sal_Int8 GalleryBrowser2::ExecuteDrop( const ExecuteDropEvent& rEvt ) if( mpCurTheme ) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos ); - const sal_uIntPtr nInsertPos = (nItemId ? (nItemId - 1) : mpCurTheme->GetObjectCount()); + const sal_uInt32 nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos ); + const sal_uInt32 nInsertPos = (nItemId ? (nItemId - 1) : mpCurTheme->GetObjectCount()); if( mpCurTheme->IsDragging() ) mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos ); @@ -576,7 +576,7 @@ void GalleryBrowser2::StartDrag( const Point* pDragPoint ) if( mpCurTheme ) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos ); if( nItemId ) mpCurTheme->StartDrag( this, nItemId - 1 ); @@ -592,7 +592,7 @@ void GalleryBrowser2::TogglePreview() void GalleryBrowser2::ShowContextMenu( const Point* pContextPoint ) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos ); if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) ) { @@ -616,7 +616,7 @@ void GalleryBrowser2::ShowContextMenu( const Point* pContextPoint ) bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, vcl::Window* /*pWindow*/ ) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); bool bRet = false; svx::sidebar::GalleryControl* pParentControl = dynamic_cast(GetParent()); if (pParentControl != nullptr) @@ -781,13 +781,13 @@ void GalleryBrowser2::SetMode( GalleryBrowserMode eMode ) { Graphic aGraphic; Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); if( nItemId ) { - const sal_uIntPtr nPos = nItemId - 1; + const sal_uInt32 nPos = nItemId - 1; - mpIconView->Hide(); + mpIconView->Hide(); mpListView->Hide(); if( mpCurTheme ) @@ -835,11 +835,11 @@ void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel ) if( mpCurTheme ) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); if( nItemId ) { - sal_Int32 nNewItemId = nItemId; + sal_uInt32 nNewItemId = nItemId; switch( eTravel ) { @@ -864,7 +864,7 @@ void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel ) if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) { Graphic aGraphic; - const sal_uIntPtr nPos = nNewItemId - 1; + const sal_uInt32 nPos = nNewItemId - 1; mpCurTheme->GetGraphic( nPos, aGraphic ); mpPreview->SetGraphic( aGraphic ); @@ -890,7 +890,7 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) if( mpCurTheme ) { - for( sal_uIntPtr i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; ) + for (sal_uInt32 i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount;) { mpListView->RowInserted( i++ ); mpIconView->InsertItem( (sal_uInt16) i ); @@ -918,10 +918,10 @@ void GalleryBrowser2::ImplUpdateInfoBar() maInfoBar->SetText( mpCurTheme->GetName() ); } -sal_Int32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos ) +sal_uInt32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos ) { const Size aOutputSizePixel( GetOutputSizePixel() ); - sal_Int32 nRet = 0; + sal_uInt32 nRet = 0; if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) { @@ -942,7 +942,7 @@ sal_Int32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& r else { nRet = mpIconView->GetSelectItemId(); - rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center(); + rSelPos = mpIconView->GetItemRect(nRet).Center(); } } else @@ -970,12 +970,12 @@ sal_Int32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& r return nRet; } -void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId ) +void GalleryBrowser2::ImplSelectItemId(sal_uInt32 nItemId) { if( nItemId ) { - mpIconView->SelectItem( (sal_uInt16) nItemId ); + mpIconView->SelectItem(nItemId); mpListView->SelectRow( nItemId - 1 ); } } @@ -999,7 +999,7 @@ void GalleryBrowser2::DispatchAdd( const css::util::URL &rURL) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); if( !mpCurTheme || !nItemId ) return; @@ -1089,7 +1089,7 @@ void GalleryBrowser2::DispatchAdd( void GalleryBrowser2::Execute(const OString &rIdent) { Point aSelPos; - const sal_Int32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); + const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); if( mpCurTheme && nItemId ) { -- cgit