diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-12-18 09:54:02 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-12-18 22:14:17 +0100 |
commit | a7c772566bb8ac6a088b808cf0ef550e7b06560b (patch) | |
tree | 56dd899b4e2081d74ea590e95e70f83f64954c48 /svx | |
parent | 877ede68f31a25a76c89d47389a190b75df1757d (diff) |
coverity#1426163 Improper use of negative value
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 <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/galbrws2.hxx | 6 | ||||
-rw-r--r-- | svx/source/gallery2/galbrws2.cxx | 44 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 66 | ||||
-rw-r--r-- | svx/source/gengal/gengal.cxx | 2 |
4 files changed, 59 insertions, 59 deletions
diff --git a/svx/inc/galbrws2.hxx b/svx/inc/galbrws2.hxx index 01c7f1e6f708..cbfef1097bfc 100644 --- a/svx/inc/galbrws2.hxx +++ b/svx/inc/galbrws2.hxx @@ -100,7 +100,7 @@ private: VclPtr<GalleryToolBox> maViewBox; VclPtr<FixedLine> maSeparator; VclPtr<FixedText> maInfoBar; - sal_uIntPtr mnCurActionPos; + sal_uInt32 mnCurActionPos; GalleryBrowserMode meMode; GalleryBrowserMode meLastMode; @@ -111,8 +111,8 @@ private: void ImplUpdateViews( sal_uInt16 nSelectionId ); void ImplUpdateInfoBar(); - sal_Int32 ImplGetSelectedItemId( const Point* pSelPosPixel, Point& rSelPos ); - void ImplSelectItemId( sal_uIntPtr nItemId ); + sal_uInt32 ImplGetSelectedItemId( const Point* pSelPosPixel, Point& rSelPos ); + void ImplSelectItemId(sal_uInt32 nItemId); // Control virtual void Resize() override; 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<PopupMenu> 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<svx::sidebar::GalleryControl*>(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 ) { diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 5e060adefd3a..6e8b16c4ba1d 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -106,7 +106,7 @@ void GalleryTheme::ImplCreateSvDrawStorage() } } -bool GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, sal_Int32 nPos, GalleryObject* pExistentEntry ) +bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry) { std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE )); bool bRet = false; @@ -124,7 +124,7 @@ bool GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, sal_Int32 nPos, Ga if( !pExistentEntry ) { pEntry = new GalleryObject; - if ( nPos < sal_Int32(aObjectList.size()) ) + if ( nPos < aObjectList.size() ) { GalleryObjectList::iterator it = aObjectList.begin(); ::std::advance( it, nPos ); @@ -330,7 +330,7 @@ INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, ConvertDat return aNewURL; } -void GalleryTheme::ImplBroadcast( sal_Int32 nUpdatePos ) +void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos) { if( !IsBroadcasterLocked() ) { @@ -364,14 +364,14 @@ void GalleryTheme::UnlockBroadcaster() ImplBroadcast( 0 ); } -bool GalleryTheme::InsertObject( const SgaObject& rObj, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos) { if (!rObj.IsValid()) return false; GalleryObject* pFoundEntry = nullptr; - size_t iFoundPos = 0; - for (size_t n = aObjectList.size(); iFoundPos < n; ++iFoundPos) + sal_uInt32 iFoundPos = 0; + for (sal_uInt32 n = aObjectList.size(); iFoundPos < n; ++iFoundPos) { if (aObjectList[ iFoundPos ]->aURL == rObj.GetURL()) { @@ -409,14 +409,14 @@ bool GalleryTheme::InsertObject( const SgaObject& rObj, sal_Int32 nInsertPos ) return true; } -SgaObject* GalleryTheme::AcquireObject( sal_Int32 nPos ) +SgaObject* GalleryTheme::AcquireObject(sal_uInt32 nPos) { - return ImplReadSgaObject( aObjectList[ nPos ] ); + return ImplReadSgaObject(ImplGetGalleryObject(nPos)); } -void GalleryTheme::GetPreviewBitmapExAndStrings(sal_Int32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const +void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const { - const GalleryObject* pGalleryObject = nPos < sal_Int32(aObjectList.size()) ? aObjectList[ nPos ] : nullptr; + const GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr; if(pGalleryObject) { @@ -431,9 +431,9 @@ void GalleryTheme::GetPreviewBitmapExAndStrings(sal_Int32 nPos, BitmapEx& rBitma } } -void GalleryTheme::SetPreviewBitmapExAndStrings(sal_Int32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath) +void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath) { - GalleryObject* pGalleryObject = nPos < sal_Int32(aObjectList.size()) ? aObjectList[ nPos ] : nullptr; + GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr; if(pGalleryObject) { @@ -453,10 +453,10 @@ void GalleryTheme::ReleaseObject( SgaObject* pObject ) delete pObject; } -bool GalleryTheme::RemoveObject( sal_Int32 nPos ) +bool GalleryTheme::RemoveObject(sal_uInt32 nPos) { GalleryObject* pEntry = nullptr; - if ( nPos < sal_Int32(aObjectList.size()) ) + if ( nPos < aObjectList.size() ) { GalleryObjectList::iterator it = aObjectList.begin(); ::std::advance( it, nPos ); @@ -484,9 +484,9 @@ bool GalleryTheme::RemoveObject( sal_Int32 nPos ) return( pEntry != nullptr ); } -bool GalleryTheme::ChangeObjectPos( sal_Int32 nOldPos, sal_Int32 nNewPos ) +bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos) { - if (nOldPos == nNewPos || nOldPos >= sal_Int32(aObjectList.size())) + if (nOldPos == nNewPos || nOldPos >= aObjectList.size()) return false; GalleryObject* pEntry = aObjectList[nOldPos]; @@ -516,16 +516,16 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize Graphic aGraphic; OUString aFormat; GalleryObject* pEntry; - const size_t nCount = aObjectList.size(); + const sal_uInt32 nCount = aObjectList.size(); LockBroadcaster(); bAbortActualize = false; // reset delete flag - for (size_t i = 0; i < nCount; i++) + for (sal_uInt32 i = 0; i < nCount; i++) aObjectList[ i ]->mbDelete = false; - for(size_t i = 0; ( i < nCount ) && !bAbortActualize; i++) + for (sal_uInt32 i = 0; ( i < nCount ) && !bAbortActualize; i++) { if( pProgress ) pProgress->Update( i, nCount - 1 ); @@ -753,7 +753,7 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, bo return pRet; } -bool GalleryTheme::GetThumb( sal_Int32 nPos, BitmapEx& rBmp ) +bool GalleryTheme::GetThumb(sal_uInt32 nPos, BitmapEx& rBmp) { SgaObject* pObj = AcquireObject( nPos ); bool bRet = false; @@ -768,7 +768,7 @@ bool GalleryTheme::GetThumb( sal_Int32 nPos, BitmapEx& rBmp ) return bRet; } -bool GalleryTheme::GetGraphic( sal_Int32 nPos, Graphic& rGraphic, bool bProgress ) +bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic, bool bProgress) { const GalleryObject* pObject = ImplGetGalleryObject( nPos ); bool bRet = false; @@ -841,7 +841,7 @@ bool GalleryTheme::GetGraphic( sal_Int32 nPos, Graphic& rGraphic, bool bProgress return bRet; } -bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos) { bool bRet = false; @@ -923,7 +923,7 @@ bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_Int32 nInsertPos return bRet; } -bool GalleryTheme::GetModel( sal_Int32 nPos, SdrModel& rModel ) +bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel) { const GalleryObject* pObject = ImplGetGalleryObject( nPos ); bool bRet = false; @@ -950,7 +950,7 @@ bool GalleryTheme::GetModel( sal_Int32 nPos, SdrModel& rModel ) return bRet; } -bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos) { INetURLObject aURL( ImplCreateUniqueURL( SgaObjKind::SvDraw ) ); tools::SvRef<SotStorage> xStor( GetSvDrawStorage() ); @@ -995,7 +995,7 @@ bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_Int32 nInsertPos return bRet; } -bool GalleryTheme::GetModelStream( sal_Int32 nPos, tools::SvRef<SotStorageStream> const & rxModelStream ) +bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream> const & rxModelStream) { const GalleryObject* pObject = ImplGetGalleryObject( nPos ); bool bRet = false; @@ -1046,7 +1046,7 @@ bool GalleryTheme::GetModelStream( sal_Int32 nPos, tools::SvRef<SotStorageStream return bRet; } -bool GalleryTheme::InsertModelStream( const tools::SvRef<SotStorageStream>& rxModelStream, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, sal_uInt32 nInsertPos) { INetURLObject aURL( ImplCreateUniqueURL( SgaObjKind::SvDraw ) ); tools::SvRef<SotStorage> xStor( GetSvDrawStorage() ); @@ -1080,7 +1080,7 @@ bool GalleryTheme::InsertModelStream( const tools::SvRef<SotStorageStream>& rxMo return bRet; } -bool GalleryTheme::GetURL( sal_Int32 nPos, INetURLObject& rURL ) +bool GalleryTheme::GetURL(sal_uInt32 nPos, INetURLObject& rURL) { const GalleryObject* pObject = ImplGetGalleryObject( nPos ); bool bRet = false; @@ -1094,7 +1094,7 @@ bool GalleryTheme::GetURL( sal_Int32 nPos, INetURLObject& rURL ) return bRet; } -bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertURL(const INetURLObject& rURL, sal_uInt32 nInsertPos) { Graphic aGraphic; OUString aFormat; @@ -1119,7 +1119,7 @@ bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_Int32 nInsertPos ) return bRet; } -bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertFileOrDirURL(const INetURLObject& rFileOrDirURL, sal_uInt32 nInsertPos) { INetURLObject aURL; ::std::vector< INetURLObject > aURLVector; @@ -1167,7 +1167,7 @@ bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_I return bRet; } -bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_Int32 nInsertPos ) +bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uInt32 nInsertPos) { bool bRet = false; @@ -1264,13 +1264,13 @@ bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTran return bRet; } -void GalleryTheme::CopyToClipboard( vcl::Window* pWindow, sal_Int32 nPos ) +void GalleryTheme::CopyToClipboard(vcl::Window* pWindow, sal_uInt32 nPos) { GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false ); pTransferable->CopyToClipboard( pWindow ); } -void GalleryTheme::StartDrag( vcl::Window* pWindow, sal_Int32 nPos ) +void GalleryTheme::StartDrag(vcl::Window* pWindow, sal_uInt32 nPos) { GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true ); pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK ); @@ -1341,7 +1341,7 @@ SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const } // more recently, a 512-byte reserve buffer is written, - // to recognize them two sal_uIntPtr-Ids will be written. + // to recognize them two sal_uInt32-Ids will be written. rOStm.WriteUInt32( COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) ).WriteUInt32( COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) ); const long nReservePos = rOStm.Tell(); diff --git a/svx/source/gengal/gengal.cxx b/svx/source/gengal/gengal.cxx index 430899ef9643..fc8568b9d3cd 100644 --- a/svx/source/gengal/gengal.cxx +++ b/svx/source/gengal/gengal.cxx @@ -122,7 +122,7 @@ static void createTheme( const OUString& aThemeName, const OUString& aGalleryURL fprintf( stderr, "Failed to import '%s'\n", OUStringToOString( aIter->GetMainURL(INetURLObject::DecodeMechanism::NONE), RTL_TEXTENCODING_UTF8 ).getStr() ); else - fprintf( stderr, "Imported file '%s' (%" SAL_PRIdINT32 "u)\n", + fprintf( stderr, "Imported file '%s' (%u)\n", OUStringToOString( aIter->GetMainURL(INetURLObject::DecodeMechanism::NONE), RTL_TEXTENCODING_UTF8 ).getStr(), pGalTheme->GetObjectCount() ); } |