From bfe79b50bce44707cb2416e6ff6b7441491967bb Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 17 Jan 2015 02:00:35 +0100 Subject: fdo#39440 reduce scope of local variables This addresses some cppcheck warnings. Change-Id: If7ad3584b3124ed0b337836071af1a5bd0451d85 Reviewed-on: https://gerrit.libreoffice.org/13972 Tested-by: Jenkins Reviewed-by: Noel Grandin --- winaccessibility/source/UAccCOM/AccTable.cxx | 16 ++++++++-------- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 3 +-- xmloff/source/chart/SchXMLExport.cxx | 3 ++- xmloff/source/chart/SchXMLImport.cxx | 3 ++- xmloff/source/draw/shapeexport.cxx | 2 +- xmloff/source/forms/eventimport.cxx | 6 ++---- xmloff/source/text/XMLRedlineExport.cxx | 3 +-- xmloff/source/text/XMLTextNumRuleInfo.cxx | 2 +- xmloff/source/text/txtimp.cxx | 3 +-- xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 2 +- .../xmlsec/mscrypt/x509certificate_mscryptimpl.cxx | 12 ++++-------- xmlsecurity/source/xmlsec/nss/secerror.cxx | 6 ++---- .../xmlsec/nss/securityenvironment_nssimpl.cxx | 21 +++++++-------------- 13 files changed, 33 insertions(+), 49 deletions(-) diff --git a/winaccessibility/source/UAccCOM/AccTable.cxx b/winaccessibility/source/UAccCOM/AccTable.cxx index e739300054a1..076e92a99c5d 100644 --- a/winaccessibility/source/UAccCOM/AccTable.cxx +++ b/winaccessibility/source/UAccCOM/AccTable.cxx @@ -663,11 +663,11 @@ STDMETHODIMP CAccTable::selectRow(long row) return E_FAIL; // Select row. - long lCol, lColumnCount, lChildIndex; + long lCol, lColumnCount; lColumnCount = GetXInterface()->getAccessibleColumnCount(); for(lCol = 0; lCol < lColumnCount; lCol ++) { - lChildIndex = GetXInterface()->getAccessibleIndex(row, lCol); + long lChildIndex = GetXInterface()->getAccessibleIndex(row, lCol); pRSelection.get()->selectAccessibleChild(lChildIndex); } @@ -707,11 +707,11 @@ STDMETHODIMP CAccTable::selectColumn(long column) return E_FAIL; // Select column. - long lRow, lRowCount, lChildIndex; + long lRow, lRowCount; lRowCount = GetXInterface()->getAccessibleRowCount(); for(lRow = 0; lRow < lRowCount; lRow ++) { - lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column); + long lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column); pRSelection.get()->selectAccessibleChild(lChildIndex); } @@ -754,11 +754,11 @@ STDMETHODIMP CAccTable::unselectRow(long row) return E_FAIL; // Select column. - long lColumn, lColumnCount, lChildIndex; + long lColumn, lColumnCount; lColumnCount = GetXInterface()->getAccessibleColumnCount(); for(lColumn = 0; lColumn < lColumnCount; lColumn ++) { - lChildIndex = GetXInterface()->getAccessibleIndex(row,lColumn); + long lChildIndex = GetXInterface()->getAccessibleIndex(row,lColumn); pRSelection.get()->deselectAccessibleChild(lChildIndex); } @@ -801,12 +801,12 @@ STDMETHODIMP CAccTable::unselectColumn(long column) return E_FAIL; // Unselect columns. - long lRow, lRowCount, lChildIndex; + long lRow, lRowCount; lRowCount = GetXInterface()->getAccessibleRowCount(); for(lRow = 0; lRow < lRowCount; lRow ++) { - lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column); + long lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column); pRSelection.get()->deselectAccessibleChild(lChildIndex); } return S_OK; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index e97c133bde42..a77aba65975b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -2452,7 +2452,6 @@ void DomainMapper_Impl::ChainTextFrames() try { - bool bIsTxbxChained = false ; sal_Int32 nTxbxId1 = 0 ; //holds id for the shape in outer loop sal_Int32 nTxbxId2 = 0 ; //holds id for the shape in inner loop sal_Int32 nTxbxSeq1 = 0 ; //holds seq number for the shape in outer loop @@ -2465,7 +2464,7 @@ void DomainMapper_Impl::ChainTextFrames() for( std::vector >::iterator outer_itr = m_vTextFramesForChaining.begin(); outer_itr != m_vTextFramesForChaining.end(); ) { - bIsTxbxChained = false ; + bool bIsTxbxChained = false ; uno::Reference xTextContent1(*outer_itr, uno::UNO_QUERY_THROW); uno::Reference xPropertySet1(xTextContent1, uno::UNO_QUERY); uno::Sequence aGrabBag1; diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index ca25f2b98ab0..f854708f3566 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -1898,10 +1898,11 @@ void SchXMLExportHelper_Impl::exportPlotArea( if( xDocProp.is()) { Any aAny; - bool bFirstCol = false, bFirstRow = false; try { + bool bFirstCol = false, bFirstRow = false; + aAny = xDocProp->getPropertyValue( OUString( "DataSourceLabelsInFirstColumn" )); aAny >>= bFirstCol; diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx index ce11bea12497..ca1f63c02353 100644 --- a/xmloff/source/chart/SchXMLImport.cxx +++ b/xmloff/source/chart/SchXMLImport.cxx @@ -620,9 +620,10 @@ void SAL_CALL SchXMLImport::setTargetDocument( const uno::Reference< lang::XComp uno::Reference< container::XChild > xChild( xChartDoc, uno::UNO_QUERY ); uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartDoc, uno::UNO_QUERY ); - bool bHasOwnData = true; if( xChild.is() && xDataReceiver.is()) { + bool bHasOwnData = true; + Reference< lang::XMultiServiceFactory > xFact( xChild->getParent(), uno::UNO_QUERY ); if( xFact.is() ) { diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index 3f0858a88a66..db76c50e598e 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -1460,7 +1460,6 @@ bool XMLShapeExport::ImpExportPresentationAttributes( const uno::Reference< bean { uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() ); - bool bTemp = false; // is empty pes shape? if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("IsEmptyPresentationObject")) @@ -1473,6 +1472,7 @@ bool XMLShapeExport::ImpExportPresentationAttributes( const uno::Reference< bean // is user-transformed? if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("IsPlaceholderDependent")) { + bool bTemp = false; xPropSet->getPropertyValue("IsPlaceholderDependent") >>= bTemp; if(!bTemp) mrExport.AddAttribute(XML_NAMESPACE_PRESENTATION, XML_USER_TRANSFORMED, XML_TRUE); diff --git a/xmloff/source/forms/eventimport.cxx b/xmloff/source/forms/eventimport.cxx index 2f499e7e84f6..256649dcc902 100644 --- a/xmloff/source/forms/eventimport.cxx +++ b/xmloff/source/forms/eventimport.cxx @@ -44,8 +44,6 @@ namespace xmloff ScriptEventDescriptor* pTranslated = aTranslated.getArray(); // loop through the collected events and translate them - const PropertyValue* pEventDescription; - const PropertyValue* pEventDescriptionEnd; sal_Int32 nSeparatorPos = -1; for ( EventsVector::const_iterator aEvent = aCollectEvents.begin(); aEvent != aCollectEvents.end(); @@ -61,8 +59,8 @@ namespace xmloff OUString sLibrary; // the local macro name and the event type are specified as properties - pEventDescription = aEvent->second.getConstArray(); - pEventDescriptionEnd = pEventDescription + aEvent->second.getLength(); + const PropertyValue* pEventDescription = aEvent->second.getConstArray(); + const PropertyValue* pEventDescriptionEnd = pEventDescription + aEvent->second.getLength(); for (;pEventDescription != pEventDescriptionEnd; ++pEventDescription) { if (pEventDescription->Name == EVENT_LOCALMACRONAME || diff --git a/xmloff/source/text/XMLRedlineExport.cxx b/xmloff/source/text/XMLRedlineExport.cxx index 5aabd59fb25b..fa93ac9441d7 100644 --- a/xmloff/source/text/XMLRedlineExport.cxx +++ b/xmloff/source/text/XMLRedlineExport.cxx @@ -332,7 +332,6 @@ void XMLRedlineExport::ExportChangeInline( enum XMLTokenEnum eElement = XML_TOKEN_INVALID; Any aAny = rPropSet->getPropertyValue(sIsCollapsed); bool bCollapsed = *(sal_Bool *)aAny.getValue(); - bool bStart = true; // ignored if bCollapsed = sal_True if (bCollapsed) { eElement = XML_CHANGE; @@ -340,7 +339,7 @@ void XMLRedlineExport::ExportChangeInline( else { aAny = rPropSet->getPropertyValue(sIsStart); - bStart = *(sal_Bool *)aAny.getValue(); + const bool bStart = *(sal_Bool *)aAny.getValue(); eElement = bStart ? XML_CHANGE_START : XML_CHANGE_END; } diff --git a/xmloff/source/text/XMLTextNumRuleInfo.cxx b/xmloff/source/text/XMLTextNumRuleInfo.cxx index 02fde000dc22..cb597daf167f 100644 --- a/xmloff/source/text/XMLTextNumRuleInfo.cxx +++ b/xmloff/source/text/XMLTextNumRuleInfo.cxx @@ -115,12 +115,12 @@ void XMLTextNumRuleInfo::Set( { if ( !mbOutlineStyleAsNormalListStyle ) { - bool bIsOutline = false; Reference xNumRulesProps(mxNumRules, UNO_QUERY); if ( xNumRulesProps.is() && xNumRulesProps->getPropertySetInfo()-> hasPropertyByName( msNumberingIsOutline ) ) { + bool bIsOutline = false; xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline; bSuppressListStyle = bIsOutline; } diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx index a7e781bcbc47..7be24938e296 100644 --- a/xmloff/source/text/txtimp.cxx +++ b/xmloff/source/text/txtimp.cxx @@ -2114,14 +2114,13 @@ void XMLTextImportHelper::SetRuby( xPropSet->setPropertyValue(sRubyText, makeAny(rText)); // the ruby style (ruby-adjust) - XMLPropStyleContext *pStyle = 0; if (!rStyleName.isEmpty() && m_pImpl->m_xAutoStyles.Is()) { const SvXMLStyleContext* pTempStyle = static_cast(&m_pImpl->m_xAutoStyles)-> FindStyleChildContext( XML_STYLE_FAMILY_TEXT_RUBY, rStyleName, true ); - pStyle = const_cast(PTR_CAST(XMLPropStyleContext,pTempStyle)); + XMLPropStyleContext *pStyle = const_cast(PTR_CAST(XMLPropStyleContext,pTempStyle)); if (NULL != pStyle) pStyle->FillPropertySet( xPropSet ); diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index 59148611a702..f66bbfcd8ea8 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -1051,9 +1051,9 @@ void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible SAL_WARN( "xmlscript.xmldlg", "unexpected property type for \"Enabled\": not bool!" ); } - bool bVisible = true; if (supportVisible) try { + bool bVisible = true; if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible) { diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx index 48fc40e8d27b..e7cfae421fb2 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx @@ -198,7 +198,6 @@ sal_Int16 SAL_CALL X509Certificate_MSCryptImpl :: getVersion() throw ( ::com::su OUString SAL_CALL X509Certificate_MSCryptImpl :: getIssuerName() throw ( ::com::sun::star::uno::RuntimeException) { if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) { - char* issuer ; DWORD cbIssuer ; cbIssuer = CertNameToStr( @@ -210,7 +209,7 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getIssuerName() throw ( ::com:: // Here the cbIssuer count the last 0x00 , take care. if( cbIssuer != 0 ) { - issuer = new char[ cbIssuer ] ; + char* issuer = new char[ cbIssuer ] ; if( issuer == NULL ) throw RuntimeException() ; @@ -249,7 +248,6 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: { if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) { - wchar_t* subject ; DWORD cbSubject ; cbSubject = CertNameToStrW( @@ -261,7 +259,7 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: if( cbSubject != 0 ) { - subject = new wchar_t[ cbSubject ] ; + wchar_t* subject = new wchar_t[ cbSubject ] ; if( subject == NULL ) throw RuntimeException() ; @@ -371,11 +369,10 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > > SAL_CALL X509Certificate_MSCryptImpl :: getExtensions() throw ( ::com::sun::star::uno::RuntimeException ) { if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL && m_pCertContext->pCertInfo->cExtension != 0 ) { CertificateExtension_XmlSecImpl* xExtn ; - CERT_EXTENSION* pExtn ; Sequence< Reference< XCertificateExtension > > xExtns( m_pCertContext->pCertInfo->cExtension ) ; for( unsigned int i = 0; i < m_pCertContext->pCertInfo->cExtension; i++ ) { - pExtn = &(m_pCertContext->pCertInfo->rgExtension[i]) ; + CERT_EXTENSION* pExtn = &(m_pCertContext->pCertInfo->rgExtension[i]) ; OUString objId = OUString::createFromAscii( pExtn->pszObjId ); @@ -401,12 +398,11 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > SAL_CALL X509Certificate_MSCryptImpl :: findCertificateExtension( const ::com::sun::star::uno::Sequence< sal_Int8 >& /*oid*/ ) throw (::com::sun::star::uno::RuntimeException) { if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL && m_pCertContext->pCertInfo->cExtension != 0 ) { CertificateExtension_XmlSecImpl* xExtn ; - CERT_EXTENSION* pExtn ; Sequence< Reference< XCertificateExtension > > xExtns( m_pCertContext->pCertInfo->cExtension ) ; xExtn = NULL ; for( unsigned int i = 0; i < m_pCertContext->pCertInfo->cExtension; i++ ) { - pExtn = &( m_pCertContext->pCertInfo->rgExtension[i] ) ; + CERT_EXTENSION* pExtn = &( m_pCertContext->pCertInfo->rgExtension[i] ) ; //TODO: Compare the oid if( 0 ) { diff --git a/xmlsecurity/source/xmlsec/nss/secerror.cxx b/xmlsecurity/source/xmlsec/nss/secerror.cxx index 2d140f040891..88275ce33827 100644 --- a/xmlsecurity/source/xmlsec/nss/secerror.cxx +++ b/xmlsecurity/source/xmlsec/nss/secerror.cxx @@ -64,8 +64,6 @@ void printChainFailure(CERTVerifyLog *log) { unsigned int depth = (unsigned int)-1; - const char * specificError = NULL; - const char * issuer = NULL; CERTVerifyLogNode *node = NULL; if (log->count > 0) @@ -83,8 +81,8 @@ printChainFailure(CERTVerifyLog *log) } SAL_INFO("xmlsecurity.xmlsec", " ERROR " << node->error << ": " << getCertError(node->error)); - specificError = NULL; - issuer = NULL; + const char * specificError = NULL; + const char * issuer = NULL; switch (node->error) { case SEC_ERROR_INADEQUATE_KEY_USAGE: diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx index dd3a5cc4c9cc..b4ea4ad3b4a2 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx @@ -232,7 +232,6 @@ void SecurityEnvironment_NssImpl :: setCertDb( CERTCertDBHandle* aCertDb ) throw } void SecurityEnvironment_NssImpl :: adoptSymKey( PK11SymKey* aSymKey ) throw( Exception , RuntimeException ) { - PK11SymKey* symkey ; std::list< PK11SymKey* >::iterator keyIt ; if( aSymKey != NULL ) { @@ -243,7 +242,7 @@ void SecurityEnvironment_NssImpl :: adoptSymKey( PK11SymKey* aSymKey ) throw( Ex } //If we do not find the key in the list, add a new node - symkey = PK11_ReferenceSymKey( aSymKey ) ; + PK11SymKey* symkey = PK11_ReferenceSymKey( aSymKey ) ; if( symkey == NULL ) throw RuntimeException() ; @@ -256,13 +255,12 @@ void SecurityEnvironment_NssImpl :: adoptSymKey( PK11SymKey* aSymKey ) throw( Ex } void SecurityEnvironment_NssImpl :: rejectSymKey( PK11SymKey* aSymKey ) throw( Exception , RuntimeException ) { - PK11SymKey* symkey ; std::list< PK11SymKey* >::iterator keyIt ; if( aSymKey != NULL ) { for( keyIt = m_tSymKeyList.begin() ; keyIt != m_tSymKeyList.end() ; ++keyIt ) { if( *keyIt == aSymKey ) { - symkey = *keyIt ; + PK11SymKey* symkey = *keyIt ; PK11_FreeSymKey( symkey ) ; m_tSymKeyList.erase( keyIt ) ; break ; @@ -286,7 +284,6 @@ PK11SymKey* SecurityEnvironment_NssImpl :: getSymKey( unsigned int position ) th } void SecurityEnvironment_NssImpl :: adoptPubKey( SECKEYPublicKey* aPubKey ) throw( Exception , RuntimeException ) { - SECKEYPublicKey* pubkey ; std::list< SECKEYPublicKey* >::iterator keyIt ; if( aPubKey != NULL ) { @@ -297,7 +294,7 @@ void SecurityEnvironment_NssImpl :: adoptPubKey( SECKEYPublicKey* aPubKey ) thro } //If we do not find the key in the list, add a new node - pubkey = SECKEY_CopyPublicKey( aPubKey ) ; + SECKEYPublicKey* pubkey = SECKEY_CopyPublicKey( aPubKey ) ; if( pubkey == NULL ) throw RuntimeException() ; @@ -310,13 +307,12 @@ void SecurityEnvironment_NssImpl :: adoptPubKey( SECKEYPublicKey* aPubKey ) thro } void SecurityEnvironment_NssImpl :: rejectPubKey( SECKEYPublicKey* aPubKey ) throw( Exception , RuntimeException ) { - SECKEYPublicKey* pubkey ; std::list< SECKEYPublicKey* >::iterator keyIt ; if( aPubKey != NULL ) { for( keyIt = m_tPubKeyList.begin() ; keyIt != m_tPubKeyList.end() ; ++keyIt ) { if( *keyIt == aPubKey ) { - pubkey = *keyIt ; + SECKEYPublicKey* pubkey = *keyIt ; SECKEY_DestroyPublicKey( pubkey ) ; m_tPubKeyList.erase( keyIt ) ; break ; @@ -340,7 +336,6 @@ SECKEYPublicKey* SecurityEnvironment_NssImpl :: getPubKey( unsigned int position } void SecurityEnvironment_NssImpl :: adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( Exception , RuntimeException ) { - SECKEYPrivateKey* prikey ; std::list< SECKEYPrivateKey* >::iterator keyIt ; if( aPriKey != NULL ) { @@ -351,7 +346,7 @@ void SecurityEnvironment_NssImpl :: adoptPriKey( SECKEYPrivateKey* aPriKey ) thr } //If we do not find the key in the list, add a new node - prikey = SECKEY_CopyPrivateKey( aPriKey ) ; + SECKEYPrivateKey* prikey = SECKEY_CopyPrivateKey( aPriKey ) ; if( prikey == NULL ) throw RuntimeException() ; @@ -364,13 +359,12 @@ void SecurityEnvironment_NssImpl :: adoptPriKey( SECKEYPrivateKey* aPriKey ) thr } void SecurityEnvironment_NssImpl :: rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( Exception , RuntimeException ) { - SECKEYPrivateKey* prikey ; std::list< SECKEYPrivateKey* >::iterator keyIt ; if( aPriKey != NULL ) { for( keyIt = m_tPriKeyList.begin() ; keyIt != m_tPriKeyList.end() ; ++keyIt ) { if( *keyIt == aPriKey ) { - prikey = *keyIt ; + SECKEYPrivateKey* prikey = *keyIt ; SECKEY_DestroyPrivateKey( prikey ) ; m_tPriKeyList.erase( keyIt ) ; break ; @@ -991,11 +985,10 @@ X509Certificate_NssImpl* NssCertToXCert( CERTCertificate* cert ) X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* priKey ) { - CERTCertificate* cert ; X509Certificate_NssImpl* xcert ; if( priKey != NULL ) { - cert = PK11_GetCertFromPrivateKey( priKey ) ; + CERTCertificate* cert = PK11_GetCertFromPrivateKey( priKey ) ; if( cert != NULL ) { xcert = NssCertToXCert( cert ) ; -- cgit v1.2.3