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 --- .../xmlsec/mscrypt/x509certificate_mscryptimpl.cxx | 12 ++++-------- xmlsecurity/source/xmlsec/nss/secerror.cxx | 6 ++---- .../xmlsec/nss/securityenvironment_nssimpl.cxx | 21 +++++++-------------- 3 files changed, 13 insertions(+), 26 deletions(-) (limited to 'xmlsecurity') 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