cui/source/tabpages/tpbitmap.cxx                  |   11 +-
 dbaccess/source/ui/misc/DExport.cxx               |    3 
 framework/source/uielement/statusbarmanager.cxx   |    5 -
 include/tools/stream.hxx                          |    2 
 sc/source/filter/excel/xetable.cxx                |    7 +
 sc/source/filter/xml/xmltabi.cxx                  |    3 
 sd/source/ui/remotecontrol/DiscoveryService.cxx   |    6 -
 svx/source/customshapes/EnhancedCustomShape2d.cxx |    7 -
 svx/source/engine3d/view3d.cxx                    |   13 +--
 svx/source/form/fmscriptingenv.cxx                |    5 -
 svx/source/svdraw/svdhdl.cxx                      |    7 -
 sw/source/core/text/itrform2.cxx                  |    5 -
 sw/source/core/unocore/unofield.cxx               |   87 ++++++++++------------
 tools/source/generic/config.cxx                   |   15 +--
 tools/source/stream/stream.cxx                    |   22 +----
 15 files changed, 82 insertions(+), 116 deletions(-)

New commits:
commit 78490b45c771a4c9632b324922f2c8e83f06153b
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sun Oct 21 15:04:57 2018 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon Oct 22 12:43:56 2018 +0200

    pvs-studio: V668 no sense testing against null as memory was allocated by 
new
    
    category V668 complete
    
    Change-Id: I986d4cb89a7c72d54d71ea01fc598a9958deee24
    Reviewed-on: https://gerrit.libreoffice.org/62138
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/cui/source/tabpages/tpbitmap.cxx b/cui/source/tabpages/tpbitmap.cxx
index e2a80c4d9473..d7af780b41aa 100644
--- a/cui/source/tabpages/tpbitmap.cxx
+++ b/cui/source/tabpages/tpbitmap.cxx
@@ -295,13 +295,10 @@ void SvxBitmapTabPage::Reset( const SfxItemSet* rAttrs )
     std::unique_ptr<GraphicObject> pGraphicObject;
     pGraphicObject.reset( new GraphicObject(aItem.GetGraphicObject()) );
 
-    if(pGraphicObject)
-    {
-        BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
-        Size aTempBitmapSize = aBmpEx.GetSizePixel();
-        rBitmapSize = PixelToLogic( aTempBitmapSize, 
MapMode(MapUnit::Map100thMM));
-        CalculateBitmapPresetSize();
-    }
+    BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
+    Size aTempBitmapSize = aBmpEx.GetSizePixel();
+    rBitmapSize = PixelToLogic( aTempBitmapSize, MapMode(MapUnit::Map100thMM));
+    CalculateBitmapPresetSize();
 
     bool bTiled = false; bool bStretched = false;
     if(rAttrs->GetItemState( XATTR_FILLBMP_TILE ) != SfxItemState::DONTCARE)
diff --git a/dbaccess/source/ui/misc/DExport.cxx 
b/dbaccess/source/ui/misc/DExport.cxx
index d5032b306f85..0fb7b3c47d04 100644
--- a/dbaccess/source/ui/misc/DExport.cxx
+++ b/dbaccess/source/ui/misc/DExport.cxx
@@ -673,8 +673,7 @@ void ODatabaseExport::CreateDefaultColumn(const OUString& 
_rColumnName)
 bool ODatabaseExport::createRowSet()
 {
     m_pUpdateHelper.reset(new 
OParameterUpdateHelper(createPreparedStatment(m_xConnection->getMetaData(),m_xTable,m_vColumnPositions)));
-
-    return m_pUpdateHelper != nullptr;
+    return true;
 }
 
 bool ODatabaseExport::executeWizard(const OUString& _rTableName, const Any& 
_aTextColor, const FontDescriptor& _rFont)
diff --git a/framework/source/uielement/statusbarmanager.cxx 
b/framework/source/uielement/statusbarmanager.cxx
index a071889c8f23..f1195068a464 100644
--- a/framework/source/uielement/statusbarmanager.cxx
+++ b/framework/source/uielement/statusbarmanager.cxx
@@ -370,9 +370,8 @@ void StatusBarManager::CreateControllers()
                 }
             }
 
-            if ( pController )
-                xController.set(static_cast< ::cppu::OWeakObject *>( 
pController ),
-                                uno::UNO_QUERY );
+            xController.set(static_cast< ::cppu::OWeakObject *>( pController ),
+                            uno::UNO_QUERY );
         }
 
         m_aControllerMap[nId] = xController;
diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index 5f199f64d601..4da1d2e0adb7 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -637,7 +637,7 @@ protected:
 
     /// AllocateMemory must update pBuf accordingly
     /// - pBuf: Address of new block
-    bool    AllocateMemory( std::size_t nSize );
+    void    AllocateMemory( std::size_t nSize );
 
     /// ReAllocateMemory must update the following variables:
     /// - pBuf: Address of new block
diff --git a/sc/source/filter/excel/xetable.cxx 
b/sc/source/filter/excel/xetable.cxx
index fb15e33ab75a..7ab2bd2b7809 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -2591,9 +2591,10 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& 
rRoot ) :
             break;
         }
 
+        assert(xCell && "can only reach here with xCell set");
+
         // insert the cell into the current row
-        if( xCell )
-            maRowBfr.AppendCell( xCell, bIsMergedBase );
+        maRowBfr.AppendCell( xCell, bIsMergedBase );
 
         if ( !aAddNoteText.isEmpty()  )
             mxNoteList->AppendNewRecord( new XclExpNote( GetRoot(), aScPos, 
nullptr, aAddNoteText ) );
@@ -2610,7 +2611,7 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot 
) :
                 ScRange aScRange( aScPos );
                 aScRange.aEnd.IncCol( rMergeItem.GetColMerge() - 1 );
                 aScRange.aEnd.IncRow( rMergeItem.GetRowMerge() - 1 );
-                sal_uInt32 nXFId = xCell ? xCell->GetFirstXFId() : 
EXC_XFID_NOTFOUND;
+                sal_uInt32 nXFId = xCell->GetFirstXFId();
                 // blank cells merged vertically may occur repeatedly
                 OSL_ENSURE( (aScRange.aStart.Col() == aScRange.aEnd.Col()) || 
(nScCol == nLastScCol),
                     "XclExpCellTable::XclExpCellTable - invalid repeated blank 
merged cell" );
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index 6d3735ed35cf..f63bffb4fd4e 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -345,8 +345,7 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
         pContext = new SvXMLImportContext( GetImport() );
     }
 
-    if( !pContext )
-        pContext = new SvXMLImportContext( GetImport() );
+    assert(pContext);
 
     return pContext;
 }
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx 
b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 0d999af5069a..389589be854d 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -80,6 +80,7 @@ void DiscoveryService::setupSockets()
 #ifdef MACOSX
     // Bonjour for OSX
     zService = new OSXNetworkService();
+    zService->setup();
 #endif
 
 #if HAVE_FEATURE_AVAHI
@@ -89,15 +90,14 @@ void DiscoveryService::setupSockets()
     gethostname(hostname, 1023);
 
     zService = new AvahiNetworkService(hostname);
+    zService->setup();
 #endif
 
 #ifdef _WIN32
     zService = new WINNetworkService();
+    zService->setup();
 #endif
 
-    if (zService)
-        zService->setup();
-
     // Old implementation for backward compatibility matter
     mSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
     if (mSocket == -1)
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx 
b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index 307f5de5a364..20e2da61d404 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -2040,11 +2040,8 @@ void EnhancedCustomShape2d::CreateSubPath(
                 aTempSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
             }
 
-            if(pObj)
-            {
-                pObj->SetMergedItemSet(aTempSet);
-                rObjectList.push_back(std::pair< SdrPathObj*, double >(pObj, 
dBrightness));
-            }
+            pObj->SetMergedItemSet(aTempSet);
+            rObjectList.push_back(std::pair< SdrPathObj*, double >(pObj, 
dBrightness));
         }
     }
 }
diff --git a/svx/source/engine3d/view3d.cxx b/svx/source/engine3d/view3d.cxx
index e88ff0116f24..7b0bcc451b10 100644
--- a/svx/source/engine3d/view3d.cxx
+++ b/svx/source/engine3d/view3d.cxx
@@ -764,17 +764,14 @@ void E3dView::ImpCreateSingle3DObjectFlat(E3dScene* 
pScene, SdrObject* pObj, boo
         }
 
         // Set attribute
-        if(p3DObj)
-        {
-            p3DObj->NbcSetLayer(pObj->GetLayer());
+        p3DObj->NbcSetLayer(pObj->GetLayer());
 
-            p3DObj->SetMergedItemSet(aSet);
+        p3DObj->SetMergedItemSet(aSet);
 
-            p3DObj->NbcSetStyleSheet(pObj->GetStyleSheet(), true);
+        p3DObj->NbcSetStyleSheet(pObj->GetStyleSheet(), true);
 
-            // Insert a new extrude object
-            pScene->InsertObject(p3DObj);
-        }
+        // Insert a new extrude object
+        pScene->InsertObject(p3DObj);
     }
 }
 
diff --git a/svx/source/form/fmscriptingenv.cxx 
b/svx/source/form/fmscriptingenv.cxx
index 2a6ed612c658..edc281665a95 100644
--- a/svx/source/form/fmscriptingenv.cxx
+++ b/svx/source/form/fmscriptingenv.cxx
@@ -1044,10 +1044,7 @@ namespace svxform
             pScript.reset( new NewStyleUNOScript( *xObjectShell, sScriptURI ) 
);
         }
 
-        OSL_ENSURE( pScript.get(), 
"FormScriptingEnvironment::doFireScriptEvent: no script to execute!" );
-        if ( !pScript.get() )
-            // this is an internal error in the above code
-            throw RuntimeException();
+        assert(pScript && "FormScriptingEnvironment::doFireScriptEvent: no 
script to execute!");
 
         aGuard.clear();
         aSolarGuard.clear();
diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx
index 69ecdbcf63d6..dd2057ccacb7 100644
--- a/svx/source/svdraw/svdhdl.cxx
+++ b/svx/source/svdraw/svdhdl.cxx
@@ -2402,11 +2402,8 @@ void SdrCropHdl::CreateB2dIAObject()
                     }
 
                     // OVERLAYMANAGER
-                    if(pOverlayObject)
-                    {
-                        xManager->add(*pOverlayObject);
-                        maOverlayGroup.append(std::move(pOverlayObject));
-                    }
+                    xManager->add(*pOverlayObject);
+                    maOverlayGroup.append(std::move(pOverlayObject));
                 }
             }
         }
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 225bce5af04f..87749f06b2de 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1384,6 +1384,8 @@ SwLinePortion *SwTextFormatter::NewPortion( 
SwTextFormatInfo &rInf )
         }
     }
 
+    assert(pPor && "can only reach here with pPor existing");
+
     // Special portions containing numbers (footnote anchor, footnote number,
     // numbering) can be contained in a rotated portion, if the user
     // choose a rotated character attribute.
@@ -1458,8 +1460,7 @@ SwLinePortion *SwTextFormatter::NewPortion( 
SwTextFormatInfo &rInf )
         m_pCurr->SetAscent( pPor->GetAscent() );
     }
 
-    OSL_ENSURE( !pPor || pPor->Height(),
-            "SwTextFormatter::NewPortion: something went wrong");
+    OSL_ENSURE(pPor->Height(), "SwTextFormatter::NewPortion: something went 
wrong");
     if( pPor->IsPostItsPortion() && rInf.X() >= rInf.Width() && rInf.GetFly() )
     {
         delete pPor;
diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index bfde7f014f88..937ec468c5f3 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -1899,62 +1899,61 @@ void SAL_CALL SwXTextField::attach(
         break;
         default: OSL_FAIL("What kind of type is that?");
     }
+
     if (!xField)
         throw uno::RuntimeException("no SwField created?");
-    if (xField)
-    {
-        xField->SetAutomaticLanguage(!m_pImpl->m_pProps->bBool4);
-        SwFormatField aFormat(*xField);
 
-        UnoActionContext aCont(pDoc);
-        if (aPam.HasMark() &&
-            m_pImpl->m_nServiceId != SwServiceType::FieldTypeAnnotation)
-        {
-            pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam);
-        }
+    xField->SetAutomaticLanguage(!m_pImpl->m_pProps->bBool4);
+    SwFormatField aFormat(*xField);
 
-        SwXTextCursor const*const 
pTextCursor(dynamic_cast<SwXTextCursor*>(pCursor));
-        const bool bForceExpandHints(
-            pTextCursor
-            && pTextCursor->IsAtEndOfMeta() );
-        const SetAttrMode nInsertFlags =
-            bForceExpandHints
-            ? SetAttrMode::FORCEHINTEXPAND
-            : SetAttrMode::DEFAULT;
+    UnoActionContext aCont(pDoc);
+    if (aPam.HasMark() &&
+        m_pImpl->m_nServiceId != SwServiceType::FieldTypeAnnotation)
+    {
+        pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam);
+    }
 
-        if (*aPam.GetPoint() != *aPam.GetMark() &&
-            m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation)
-        {
-            // Make sure we always insert the field at the end
-            SwPaM aEnd(*aPam.End(), *aPam.End());
-            pDoc->getIDocumentContentOperations().InsertPoolItem(aEnd, 
aFormat, nInsertFlags);
-        }
-        else
-            pDoc->getIDocumentContentOperations().InsertPoolItem(aPam, 
aFormat, nInsertFlags);
+    SwXTextCursor const*const 
pTextCursor(dynamic_cast<SwXTextCursor*>(pCursor));
+    const bool bForceExpandHints(
+        pTextCursor
+        && pTextCursor->IsAtEndOfMeta() );
+    const SetAttrMode nInsertFlags =
+        bForceExpandHints
+        ? SetAttrMode::FORCEHINTEXPAND
+        : SetAttrMode::DEFAULT;
+
+    if (*aPam.GetPoint() != *aPam.GetMark() &&
+        m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation)
+    {
+        // Make sure we always insert the field at the end
+        SwPaM aEnd(*aPam.End(), *aPam.End());
+        pDoc->getIDocumentContentOperations().InsertPoolItem(aEnd, aFormat, 
nInsertFlags);
+    }
+    else
+        pDoc->getIDocumentContentOperations().InsertPoolItem(aPam, aFormat, 
nInsertFlags);
 
-        SwTextAttr* pTextAttr = 
aPam.GetNode().GetTextNode()->GetFieldTextAttrAt( 
aPam.GetPoint()->nContent.GetIndex()-1, true );
+    SwTextAttr* pTextAttr = aPam.GetNode().GetTextNode()->GetFieldTextAttrAt( 
aPam.GetPoint()->nContent.GetIndex()-1, true );
 
-        // What about updating the fields? (see fldmgr.cxx)
-        if (!pTextAttr)
-            throw uno::RuntimeException("no SwTextAttr inserted?");  // could 
theoretically happen, if paragraph is full
+    // What about updating the fields? (see fldmgr.cxx)
+    if (!pTextAttr)
+        throw uno::RuntimeException("no SwTextAttr inserted?");  // could 
theoretically happen, if paragraph is full
 
-        const SwFormatField& rField = pTextAttr->GetFormatField();
-        m_pImpl->m_pFormatField = &rField;
+    const SwFormatField& rField = pTextAttr->GetFormatField();
+    m_pImpl->m_pFormatField = &rField;
 
-        if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION
-             && *aPam.GetPoint() != *aPam.GetMark() )
+    if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION
+         && *aPam.GetPoint() != *aPam.GetMark() )
+    {
+        // create annotation mark
+        const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* 
>(pTextAttr->GetFormatField().GetField());
+        OSL_ENSURE( pPostItField != nullptr, 
"<SwXTextField::attachToRange(..)> - annotation field missing!" );
+        if ( pPostItField != nullptr )
         {
-            // create annotation mark
-            const SwPostItField* pPostItField = dynamic_cast< const 
SwPostItField* >(pTextAttr->GetFormatField().GetField());
-            OSL_ENSURE( pPostItField != nullptr, 
"<SwXTextField::attachToRange(..)> - annotation field missing!" );
-            if ( pPostItField != nullptr )
-            {
-                IDocumentMarkAccess* pMarksAccess = 
pDoc->getIDocumentMarkAccess();
-                pMarksAccess->makeAnnotationMark( aPam, 
pPostItField->GetName() );
-            }
+            IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
+            pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() );
         }
-
     }
+
     xField.reset();
 
     assert(m_pImpl->m_pFormatField);
diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx
index a9ee7f1cc274..f27542070fb2 100644
--- a/tools/source/generic/config.cxx
+++ b/tools/source/generic/config.cxx
@@ -410,21 +410,14 @@ static sal_uInt8* ImplGetConfigBuffer( const 
ImplConfigData* pData, sal_uInt32&
     if ( !nBufLen )
     {
         pWriteBuf = new sal_uInt8[nLineEndLen];
-        if ( pWriteBuf )
-        {
-            pWriteBuf[0] = aLineEndBuf[0];
-            if ( nLineEndLen == 2 )
-                pWriteBuf[1] = aLineEndBuf[1];
-            return pWriteBuf;
-        }
-        else
-            return nullptr;
+        pWriteBuf[0] = aLineEndBuf[0];
+        if ( nLineEndLen == 2 )
+            pWriteBuf[1] = aLineEndBuf[1];
+        return pWriteBuf;
     }
 
     // Allocate new write buffer (caller frees it)
     pWriteBuf = new sal_uInt8[nBufLen];
-    if ( !pWriteBuf )
-        return nullptr;
 
     // fill buffer
     pBuf = pWriteBuf;
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 21b317e774b9..e7d21d950e39 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1632,13 +1632,9 @@ SvMemoryStream::SvMemoryStream( std::size_t nInitSize, 
std::size_t nResizeOffset
     pBuf        = nullptr;
     if( nResize != 0 && nResize < 16 )
         nResize = 16;
-    if( nInitSize && !AllocateMemory( nInitSize ) )
-    {
-        SetError( SVSTREAM_OUTOFMEMORY );
-        nSize = 0;
-    }
-    else
-        nSize = nInitSize;
+    if( nInitSize )
+        AllocateMemory( nInitSize );
+    nSize = nInitSize;
     SetBufferSize( 64 );
 }
 
@@ -1801,10 +1797,9 @@ void SvMemoryStream::ResetError()
     SvStream::ClearError();
 }
 
-bool SvMemoryStream::AllocateMemory( std::size_t nNewSize )
+void SvMemoryStream::AllocateMemory( std::size_t nNewSize )
 {
     pBuf = new sal_uInt8[nNewSize];
-    return( pBuf != nullptr );
 }
 
 // (using Bozo algorithm)
@@ -1887,13 +1882,8 @@ void* SvMemoryStream::SwitchBuffer()
     ResetError();
 
     std::size_t nInitSize = 512;
-    if( !AllocateMemory(nInitSize) )
-    {
-        SetError( SVSTREAM_OUTOFMEMORY );
-        nSize = 0;
-    }
-    else
-        nSize = nInitSize;
+    AllocateMemory(nInitSize);
+    nSize = nInitSize;
 
     SetBufferSize( 64 );
     return pRetVal;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to