[Libreoffice-commits] core.git: 2 commits - chart2/source dbaccess/source extensions/source include/basegfx include/cppuhelper package/source sc/source sd/source svtools/source sw/qa sw/source vcl/source xmloff/source

Michael Stahl mstahl at redhat.com
Fri Mar 13 08:29:40 PDT 2015


 chart2/source/view/axes/ScaleAutomatism.cxx                 |    2 
 chart2/source/view/main/ChartView.cxx                       |    3 
 dbaccess/source/core/api/RowSetCache.cxx                    |    2 
 extensions/source/plugin/base/xplugin.cxx                   |   93 ++++++++----
 extensions/source/plugin/inc/plugin/impl.hxx                |    1 
 include/basegfx/range/b2dconnectedranges.hxx                |    2 
 include/cppuhelper/interfacecontainer.hxx                   |    2 
 package/source/zippackage/ZipPackageFolderEnumeration.cxx   |    2 
 sc/source/core/data/dociter.cxx                             |    4 
 sd/source/core/shapelist.cxx                                |    2 
 sd/source/ui/view/ViewShellManager.cxx                      |    2 
 svtools/source/control/calendar.cxx                         |   18 +-
 sw/qa/extras/uiwriter/uiwriter.cxx                          |    2 
 sw/source/core/access/accmap.cxx                            |    2 
 vcl/source/control/field2.cxx                               |    4 
 xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx |    2 
 16 files changed, 89 insertions(+), 54 deletions(-)

New commits:
commit 040cf119d184233971b9cbcc9c5478d9089f9157
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 13 16:07:36 2015 +0100

    extensions: PVS-Studio V595 The 'm_pPlugin' pointer could be null
    
    The plugin streams are a bit of a disaster area: there are 2 of them
    with a common base class and the PluginInputStream is a UNO service.
    
    The m_pPlugin gets reset in PluginStream::setMode(-1), which is called
    by the plugin itself.  So those PluginStream/PluginInputStream methods
    that are called via UNO (including dtors) need to check that m_pPlugin
    isn't null, but they also lock member access with m_pPlugin's mutex.
    
    Try to ensure that that works by ensuring that the plugin is still alive
    with a WeakReference, *and* checking that m_pPlugin isn't null.
    
    Change-Id: I925b30dd7cad3d3587fcc6b10f888e30d45fc38a

diff --git a/extensions/source/plugin/base/xplugin.cxx b/extensions/source/plugin/base/xplugin.cxx
index 74106a2..62451c7 100644
--- a/extensions/source/plugin/base/xplugin.cxx
+++ b/extensions/source/plugin/base/xplugin.cxx
@@ -930,8 +930,10 @@ PluginDescription XPlugin_Impl::fitDescription( const OUString& rURL )
 
 
 PluginStream::PluginStream( XPlugin_Impl* pPlugin,
-                            const char* url, sal_uInt32 len, sal_uInt32 lastmod ) :
-        m_pPlugin( pPlugin )
+                            const char* url, sal_uInt32 len, sal_uInt32 lastmod)
+    : m_wPlugin(static_cast< ::cppu::OWeakObject* >(pPlugin))
+    , m_pPlugin(pPlugin)
+
 {
     memset( &m_aNPStream, 0, sizeof( m_aNPStream ) );
     m_aNPStream.url             = strdup( url );
@@ -941,14 +943,19 @@ PluginStream::PluginStream( XPlugin_Impl* pPlugin,
 
 PluginStream::~PluginStream()
 {
-    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
-
-    if( m_pPlugin && m_pPlugin->getPluginComm() )
+    uno::Reference<uno::XInterface> const xPlugin(m_wPlugin);
+    XPlugin_Impl *const pPlugin(m_pPlugin);
+    if (xPlugin.is() && pPlugin)
     {
-        m_pPlugin->getPluginComm()->NPP_DestroyStream( &m_pPlugin->getNPPInstance(),
-                                                       &m_aNPStream, NPRES_DONE );
-        m_pPlugin->checkListeners( m_aNPStream.url );
-        m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
+        Guard< Mutex > aGuard( pPlugin->getMutex() );
+
+        if( m_pPlugin && m_pPlugin->getPluginComm() )
+        {
+            m_pPlugin->getPluginComm()->NPP_DestroyStream( &m_pPlugin->getNPPInstance(),
+                                                           &m_aNPStream, NPRES_DONE );
+            m_pPlugin->checkListeners( m_aNPStream.url );
+            m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
+        }
     }
     ::free( (void*)m_aNPStream.url );
 }
@@ -962,6 +969,7 @@ PluginInputStream::PluginInputStream( XPlugin_Impl* pPlugin,
         m_nMode( NP_NORMAL ),
         m_nWritePos( 0 )
 {
+    assert(m_pPlugin);
     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
 
     m_pPlugin->getInputStreams().push_back( this );
@@ -991,30 +999,38 @@ PluginInputStream::PluginInputStream( XPlugin_Impl* pPlugin,
 
 PluginInputStream::~PluginInputStream()
 {
-    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
-
-    m_pPlugin->getInputStreams().remove( this );
-
     OUString aFile( m_aFileStream.GetFileName() );
 
     m_aFileStream.Close();
-    if( m_pPlugin )
+
+    uno::Reference<uno::XInterface> const xPlugin(m_wPlugin);
+    XPlugin_Impl *const pPlugin(m_pPlugin);
+    if (xPlugin.is() && pPlugin)
     {
-        OString aFileName(OUStringToOString(aFile, m_pPlugin->getTextEncoding()));
-        if( m_pPlugin->getPluginComm() && m_nMode != -1 )
-            // mode -1 means either an error occurred,
-            // or the plugin is already disposing
+        Guard< Mutex > aGuard( pPlugin->getMutex() );
+
+        pPlugin->getInputStreams().remove( this );
+
+        if( m_pPlugin )
         {
-            m_pPlugin->getPluginComm()->addFileToDelete( aFile );
-            if( m_nMode == NP_ASFILE )
+            OString aFileName(OUStringToOString(aFile, m_pPlugin->getTextEncoding()));
+            if( m_pPlugin->getPluginComm() && m_nMode != -1 )
+                // mode -1 means either an error occurred,
+                // or the plugin is already disposing
             {
-                m_pPlugin->getPluginComm()->
-                    NPP_StreamAsFile( &m_pPlugin->getNPPInstance(),
-                                      &m_aNPStream,
-                                      aFileName.getStr() );
+                m_pPlugin->getPluginComm()->addFileToDelete( aFile );
+                if( m_nMode == NP_ASFILE )
+                {
+                    m_pPlugin->getPluginComm()->
+                        NPP_StreamAsFile( &m_pPlugin->getNPPInstance(),
+                                          &m_aNPStream,
+                                          aFileName.getStr() );
+                }
+                m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
+                m_pPlugin->getInputStreams().remove( this );
             }
-            m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
-            m_pPlugin->getInputStreams().remove( this );
+            else
+                osl::File::remove( aFile );
         }
         else
             osl::File::remove( aFile );
@@ -1058,21 +1074,28 @@ void PluginInputStream::load()
 
 void PluginInputStream::setMode( sal_Int32 nMode )
 {
+    assert(m_pPlugin); // this is currently only called from two places...
     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
 
     m_nMode = nMode;
 
     // invalidation by plugin
-    if( m_nMode == -1 && m_pPlugin )
+    if (m_nMode == -1)
     {
         m_pPlugin->getInputStreams().remove( this );
         m_pPlugin = NULL;
+        m_wPlugin.clear();
     }
 }
 
 void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) throw(std::exception)
 {
-    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
+    uno::Reference<uno::XInterface> const xPlugin(m_wPlugin);
+    XPlugin_Impl *const pPlugin(m_pPlugin);
+    if (!xPlugin.is() || !pPlugin)
+        return;
+
+    Guard< Mutex > aGuard( pPlugin->getMutex() );
 
     m_aFileStream.Seek( STREAM_SEEK_TO_END );
     m_aFileStream.Write( Buffer.getConstArray(), Buffer.getLength() );
@@ -1120,7 +1143,12 @@ void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) throw(std
 
 void PluginInputStream::closeOutput() throw(std::exception)
 {
-    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
+    uno::Reference<uno::XInterface> const xPlugin(m_wPlugin);
+    XPlugin_Impl *const pPlugin(m_pPlugin);
+    if (!xPlugin.is() || !pPlugin)
+        return;
+
+    Guard< Mutex > aGuard( pPlugin->getMutex() );
 
     flush();
     m_xSource = uno::Reference< com::sun::star::io::XActiveDataSource >();
@@ -1128,7 +1156,12 @@ void PluginInputStream::closeOutput() throw(std::exception)
 
 sal_uInt32 PluginInputStream::read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size )
 {
-    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
+    uno::Reference<uno::XInterface> const xPlugin(m_wPlugin);
+    XPlugin_Impl *const pPlugin(m_pPlugin);
+    if (!xPlugin.is() || !pPlugin)
+        return 0;
+
+    Guard< Mutex > aGuard( pPlugin->getMutex() );
 
     if( m_nMode != NP_SEEK )
         return 0;
diff --git a/extensions/source/plugin/inc/plugin/impl.hxx b/extensions/source/plugin/inc/plugin/impl.hxx
index 6f1cc35..7ec12f7 100644
--- a/extensions/source/plugin/inc/plugin/impl.hxx
+++ b/extensions/source/plugin/inc/plugin/impl.hxx
@@ -331,6 +331,7 @@ enum PluginStreamType { InputStream, OutputStream };
 class PluginStream
 {
 protected:
+    css::uno::WeakReference<css::uno::XInterface> m_wPlugin;
     XPlugin_Impl*       m_pPlugin;
     NPStream            m_aNPStream;
 public:
commit 077723111292ea615437f3bc2f1e47cf77d7ad42
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 13 14:16:51 2015 +0100

    V803 decreased performance postfix increment
    
    These are pretty silly anyway, but apparently it complains even about
    integer variables which make this rather a waste of time.
    
    Change-Id: I15e847d33d5decd2adcab04e4f1567d3997d28a2

diff --git a/chart2/source/view/axes/ScaleAutomatism.cxx b/chart2/source/view/axes/ScaleAutomatism.cxx
index 5747d81..f58bde4 100644
--- a/chart2/source/view/axes/ScaleAutomatism.cxx
+++ b/chart2/source/view/axes/ScaleAutomatism.cxx
@@ -570,7 +570,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis(
     {
     case DAY:
         if( rExplicitScale.ShiftedCategoryPosition )
-            aMaxDate++;//for explicit scales we need one interval more (maximum excluded)
+            ++aMaxDate; //for explicit scales we need one interval more (maximum excluded)
         break;
     case MONTH:
         aMinDate.SetDay(1);
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 7ae6465..ad10fb5 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1888,7 +1888,8 @@ bool ChartView::getExplicitValuesForAxis(
                 switch( rExplicitScale.TimeResolution )
                 {
                 case ::com::sun::star::chart::TimeUnit::DAY:
-                    aMaxDate--;break;
+                    --aMaxDate;
+                    break;
                 case ::com::sun::star::chart::TimeUnit::MONTH:
                     aMaxDate = DateHelper::GetDateSomeMonthsAway(aMaxDate,-1);
                     break;
diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx
index ba588c9..4a10be4 100644
--- a/dbaccess/source/core/api/RowSetCache.cxx
+++ b/dbaccess/source/core/api/RowSetCache.cxx
@@ -1680,7 +1680,7 @@ bool ORowSetCache::reFillMatrix(sal_Int32 _nNewStartPos, sal_Int32 _nNewEndPos)
 bool ORowSetCache::fill(ORowSetMatrix::iterator& _aIter, const ORowSetMatrix::const_iterator& _aEnd, sal_Int32& _nPos, bool _bCheck)
 {
     const sal_Int32 nColumnCount = m_xMetaData->getColumnCount();
-    for(; _bCheck && _aIter != _aEnd; _aIter++, _nPos++)
+    for (; _bCheck && _aIter != _aEnd; ++_aIter, ++_nPos)
     {
         if ( !_aIter->is() )
             *_aIter = new ORowSetValueVector(nColumnCount);
diff --git a/include/basegfx/range/b2dconnectedranges.hxx b/include/basegfx/range/b2dconnectedranges.hxx
index 66a8a94..6473b2d 100644
--- a/include/basegfx/range/b2dconnectedranges.hxx
+++ b/include/basegfx/range/b2dconnectedranges.hxx
@@ -190,7 +190,7 @@ namespace basegfx
                         }
                         else
                         {
-                            aCurrAggregate++;
+                            ++aCurrAggregate;
                         }
                     }
                 }
diff --git a/include/cppuhelper/interfacecontainer.hxx b/include/cppuhelper/interfacecontainer.hxx
index d8038ee..ac89d61 100644
--- a/include/cppuhelper/interfacecontainer.hxx
+++ b/include/cppuhelper/interfacecontainer.hxx
@@ -69,7 +69,7 @@ inline ::com::sun::star::uno::Sequence< key > OMultiTypeInterfaceContainerHelper
             if( static_cast<OInterfaceContainerHelper*>((*iter).second)->getLength() )
                 // yes, put the type in the array
                 pArray[i++] = (*iter).first;
-            iter++;
+            ++iter;
         }
         if( i != nSize ) {
             // may be empty container, reduce the sequence to the right size
diff --git a/package/source/zippackage/ZipPackageFolderEnumeration.cxx b/package/source/zippackage/ZipPackageFolderEnumeration.cxx
index 7644cbb..1699ce6 100644
--- a/package/source/zippackage/ZipPackageFolderEnumeration.cxx
+++ b/package/source/zippackage/ZipPackageFolderEnumeration.cxx
@@ -51,7 +51,7 @@ uno::Any SAL_CALL ZipPackageFolderEnumeration::nextElement(  )
     if (aIterator == rContents.end() )
         throw container::NoSuchElementException(THROW_WHERE );
     aAny <<= (*aIterator).second->xTunnel;
-    aIterator++;
+    ++aIterator;
     return aAny;
 }
 
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 6ab77bc..46690d7 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -2029,7 +2029,7 @@ bool ScHorizontalCellIterator::SkipInvalidInRow()
         {
             debugiter("skip empty cells at column %d, row %d\n",
                       (int)maColPos->mnCol, (int)nRow);
-            maColPos++;
+            ++maColPos;
         }
     }
 
@@ -2068,7 +2068,7 @@ void ScHorizontalCellIterator::Advance()
     assert (mbMore);
     assert (maColPos != maColPositions.end());
 
-    maColPos++;
+    ++maColPos;
 
     SkipInvalid();
 }
diff --git a/sd/source/core/shapelist.cxx b/sd/source/core/shapelist.cxx
index a265e9c..47ba5e2 100644
--- a/sd/source/core/shapelist.cxx
+++ b/sd/source/core/shapelist.cxx
@@ -133,7 +133,7 @@ void ShapeList::seekShape( sal_uInt32 nIndex )
 {
     maIter = maShapeList.begin();
     while( nIndex-- && (maIter != maShapeList.end()) )
-        maIter++;
+        ++maIter;
 }
 
 bool ShapeList::hasMore() const
diff --git a/sd/source/ui/view/ViewShellManager.cxx b/sd/source/ui/view/ViewShellManager.cxx
index ad678af..4587c05 100644
--- a/sd/source/ui/view/ViewShellManager.cxx
+++ b/sd/source/ui/view/ViewShellManager.cxx
@@ -997,7 +997,7 @@ IMPL_LINK(ViewShellManager::Implementation, WindowEventHandler, VclWindowEvent*,
             {
                 for (ActiveShellList::iterator aI(maActiveViewShells.begin());
                      aI!=maActiveViewShells.end();
-                     aI++)
+                     ++aI)
                 {
                     if (pEventWindow == static_cast< ::vcl::Window*>(aI->GetWindow()))
                     {
diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx
index c2dc94a..72f2966 100644
--- a/svtools/source/control/calendar.cxx
+++ b/svtools/source/control/calendar.cxx
@@ -93,7 +93,7 @@ static void ImplCalendarSelectDateRange( IntDateSet* pTable,
         while ( aStartDate <= aEndDate )
         {
             pTable->insert( aStartDate.GetDate() );
-            aStartDate++;
+            ++aStartDate;
         }
     }
     else
@@ -443,7 +443,7 @@ void Calendar::ImplFormat()
         aTempDate += nDaysInMonth;
     }
     Date aTempDate2 = aTempDate;
-    aTempDate2--;
+    --aTempDate2;
     nDaysInMonth = aTempDate2.GetDaysInMonth();
     aTempDate2 -= nDaysInMonth-1;
     nWeekDay = (sal_uInt16)aTempDate2.GetDayOfWeek();
@@ -1086,7 +1086,7 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
     Date    aTempDate = rDate;
 
     if ( !(nHitTest & CALENDAR_HITTEST_DAY) )
-        aTempDate--;
+        --aTempDate;
 
     if ( mbMultiSelection )
     {
@@ -1231,7 +1231,7 @@ void Calendar::ImplScroll( bool bPrev )
     Date aNewFirstMonth = GetFirstMonth();
     if ( bPrev )
     {
-        aNewFirstMonth--;
+        --aNewFirstMonth;
         aNewFirstMonth -= aNewFirstMonth.GetDaysInMonth()-1;
     }
     else
@@ -1526,11 +1526,11 @@ void Calendar::KeyInput( const KeyEvent& rKEvt )
             break;
 
         case KEY_LEFT:
-            aNewDate--;
+            --aNewDate;
             break;
 
         case KEY_RIGHT:
-            aNewDate++;
+            ++aNewDate;
             break;
 
         case KEY_UP:
@@ -1897,7 +1897,7 @@ void Calendar::SetCurDate( const Date& rNewDate )
             {
                 Date aFirstDate = GetFirstMonth();
                 aFirstDate += aFirstDate.GetDaysInMonth();
-                aTempDate++;
+                ++aTempDate;
                 while ( nDateOff > aTempDate.GetDaysInMonth() )
                 {
                     aFirstDate += aFirstDate.GetDaysInMonth();
@@ -1957,7 +1957,7 @@ Date Calendar::GetLastMonth() const
     sal_uInt16 nMonthCount = GetMonthCount();
     for ( sal_uInt16 i = 0; i < nMonthCount; i++ )
         aDate += aDate.GetDaysInMonth();
-    aDate--;
+    --aDate;
     return aDate;
 }
 
@@ -2037,7 +2037,7 @@ Rectangle Calendar::GetDateRect( const Date& rDate ) const
                 }
                 else
                     nDayIndex++;
-                aLastDate++;
+                ++aLastDate;
             }
         }
     }
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index b285018..d76a27a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -337,7 +337,7 @@ void SwUiWriterTest::testFdo74981()
     aIdx = SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1);
     pTxtNode = aIdx.GetNode().GetTxtNode();
     CPPUNIT_ASSERT(pTxtNode->HasHints());
-    aIdx--;
+    --aIdx;
     pTxtNode = aIdx.GetNode().GetTxtNode();
     CPPUNIT_ASSERT(!pTxtNode->HasHints());
 }
diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index 5b41a9c..398a8a3 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -1375,7 +1375,7 @@ void SwAccessibleMap::InvalidateShapeInParaSelection()
                             mapTemp.insert( SwAccessibleContextMap_Impl::value_type( pFrm, xAcc ) );
                         }
                     }
-                    nStartIndex++;
+                    ++nStartIndex;
                 }
             }
         }
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index efd5549..c356a82 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -1239,12 +1239,12 @@ static void ImplDateIncrementDay( Date& rDate, bool bUp )
     if ( bUp )
     {
         if ( (rDate.GetDay() != 31) || (rDate.GetMonth() != 12) || (rDate.GetYear() != 9999) )
-            rDate++;
+            ++rDate;
     }
     else
     {
         if ( (rDate.GetDay() != 1 ) || (rDate.GetMonth() != 1) || (rDate.GetYear() != 0) )
-            rDate--;
+            --rDate;
     }
 }
 
diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
index be14e0e..0e2a2cb 100644
--- a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
+++ b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
@@ -127,7 +127,7 @@ bool UnoInterfaceToUniqueIdentifierMapper::findReference( const Reference< XInte
         if( (*rIter).second.get() == xRef.get() )
             return true;
 
-        rIter++;
+        ++rIter;
     }
 
     return false;


More information about the Libreoffice-commits mailing list