Kaydet (Commit) 78490b45 authored tarafından Caolán McNamara's avatar Caolán McNamara

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: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 5c147fc5
......@@ -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)
......
......@@ -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)
......
......@@ -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;
......
......@@ -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
......
......@@ -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" );
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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));
}
}
}
......
......@@ -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);
}
}
......
......@@ -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();
......
......@@ -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));
}
}
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment