diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2014-12-17 21:16:11 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-12-18 06:39:15 +0000 |
commit | a23f6eb3ae49dfc326c6e57a8ab95a840c0661d2 (patch) | |
tree | e4bfa45604b2a62a6683573305763dd13f195e33 | |
parent | 36936c2580bf15117dd3bf775dd91340d16d3239 (diff) |
fdo#39440 reduce scope of local variables
This addresses some cppcheck warnings.
Change-Id: Ib16e4ecc0e0c43b2c1fb527eb0668a960ae9756e
Reviewed-on: https://gerrit.libreoffice.org/13513
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | idlc/source/astdump.cxx | 3 | ||||
-rw-r--r-- | idlc/source/astenum.cxx | 9 | ||||
-rw-r--r-- | idlc/source/astoperation.cxx | 3 | ||||
-rw-r--r-- | idlc/source/aststruct.cxx | 3 | ||||
-rw-r--r-- | idlc/source/idlccompile.cxx | 2 | ||||
-rw-r--r-- | l10ntools/source/helpmerge.cxx | 13 | ||||
-rw-r--r-- | l10ntools/source/xmlparse.cxx | 18 | ||||
-rw-r--r-- | lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx | 13 | ||||
-rw-r--r-- | linguistic/source/dicimp.cxx | 3 | ||||
-rw-r--r-- | linguistic/source/gciterator.cxx | 3 |
10 files changed, 26 insertions, 44 deletions
diff --git a/idlc/source/astdump.cxx b/idlc/source/astdump.cxx index 90b182c8de7d..e0f786b68505 100644 --- a/idlc/source/astdump.cxx +++ b/idlc/source/astdump.cxx @@ -69,11 +69,10 @@ bool AstModule::dump(RegistryKey& rKey) DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - AstDeclaration* pDecl = NULL; sal_uInt16 index = 0; while ( iter != end ) { - pDecl = *iter; + AstDeclaration* pDecl = *iter; if ( pDecl->getNodeType() == NT_const && pDecl->isInMainfile() ) { diff --git a/idlc/source/astenum.cxx b/idlc/source/astenum.cxx index 1f330b18f780..32f813803c6e 100644 --- a/idlc/source/astenum.cxx +++ b/idlc/source/astenum.cxx @@ -37,13 +37,11 @@ AstConstant* AstEnum::checkValue(AstExpression* pExpr) { DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - AstConstant* pConst = NULL; - AstDeclaration* pDecl = NULL; while ( iter != end) { - pDecl = *iter; - pConst = static_cast<AstConstant*>(pDecl); + AstDeclaration* pDecl = *iter; + AstConstant* pConst = static_cast<AstConstant*>(pDecl); if (pConst->getConstValue()->compare(pExpr)) return pConst; @@ -80,11 +78,10 @@ bool AstEnum::dump(RegistryKey& rKey) DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - AstDeclaration* pDecl = NULL; sal_uInt16 index = 0; while ( iter != end ) { - pDecl = *iter; + AstDeclaration* pDecl = *iter; if ( pDecl->getNodeType() == NT_enum_val ) static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false); diff --git a/idlc/source/astoperation.cxx b/idlc/source/astoperation.cxx index 5a38c8acbc20..ce67313a8632 100644 --- a/idlc/source/astoperation.cxx +++ b/idlc/source/astoperation.cxx @@ -60,12 +60,11 @@ bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index) { DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - AstDeclaration* pDecl = NULL; RTParamMode paramMode; sal_uInt16 paramIndex = 0; while ( iter != end ) { - pDecl = *iter; + AstDeclaration* pDecl = *iter; if ( pDecl->getNodeType() == NT_parameter ) { AstParameter* pParam = static_cast<AstParameter*>(pDecl); diff --git a/idlc/source/aststruct.cxx b/idlc/source/aststruct.cxx index 482ee73dadfa..0a85a12965fa 100644 --- a/idlc/source/aststruct.cxx +++ b/idlc/source/aststruct.cxx @@ -121,12 +121,11 @@ bool AstStruct::dump(RegistryKey& rKey) { DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - AstDeclaration* pDecl = NULL; AstMember* pMember = NULL; sal_uInt16 index = 0; while ( iter != end ) { - pDecl = *iter; + AstDeclaration* pDecl = *iter; if ( pDecl->getNodeType() == NT_member ) { pMember = static_cast<AstMember*>(pDecl); diff --git a/idlc/source/idlccompile.cxx b/idlc/source/idlccompile.cxx index 45dbfbcfb694..3d4ef7d22b1a 100644 --- a/idlc/source/idlccompile.cxx +++ b/idlc/source/idlccompile.cxx @@ -186,11 +186,11 @@ bool copyFile(const OString* source, const OString& target) } size_t totalSize = 512; - size_t readSize = 0; char pBuffer[513]; while ( !feof(pSource) ) { + size_t readSize; if ( (readSize = fread(pBuffer, 1, totalSize, pSource)) > 0 && !ferror(pSource) ) { if ( (fwrite(pBuffer, 1, readSize, pTarget)) != readSize || ferror(pTarget) ) diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index 492f6f7c9a68..7411c55b89da 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -103,9 +103,7 @@ bool HelpParser::CreatePO( return false; } - XMLHashMap* aXMLStrHM = file->GetStrings(); - LangHashMap* pElem; - XMLElement* pXMLElement = NULL; + XMLHashMap* aXMLStrHM = file->GetStrings(); std::vector<OString> order = file->getOrder(); std::vector<OString>::iterator pos; @@ -114,9 +112,9 @@ bool HelpParser::CreatePO( for( pos = order.begin(); pos != order.end() ; ++pos ) { posm = aXMLStrHM->find( *pos ); - pElem = posm->second; + LangHashMap* pElem = posm->second; - pXMLElement = (*pElem)[ "en-US" ]; + XMLElement* pXMLElement = (*pElem)[ "en-US" ]; if( pXMLElement != NULL ) { @@ -167,8 +165,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile { file->Extract(); - XMLHashMap* aXMLStrHM = file->GetStrings(); - LangHashMap* aLangHM; + XMLHashMap* aXMLStrHM = file->GetStrings(); static ResData pResData("",""); pResData.sResTyp = "help"; @@ -179,7 +176,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile for( pos = order.begin(); pos != order.end() ; ++pos ) // Merge every l10n related string in the same order as export { posm = aXMLStrHM->find( *pos ); - aLangHM = posm->second; + LangHashMap* aLangHM = posm->second; #if OSL_DEBUG_LEVEL > 2 printf("*********************DUMPING HASHMAP***************************************"); Dump(aXMLStrHM); diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 2c376cf8c675..6b2a30425848 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -89,10 +89,9 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj) if( rObj.m_pChildList ) { m_pChildList=new XMLChildNodeList(); - XMLChildNode* pNode = NULL; for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) { - pNode = (*rObj.m_pChildList)[ i ]; + XMLChildNode* pNode = (*rObj.m_pChildList)[ i ]; if( pNode != NULL) { switch(pNode->GetNodeType()) @@ -529,12 +528,11 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur ) { case XML_NODE_TYPE_FILE: { - XMLParentNode* pElement; if( GetChildList()) { for ( size_t i = 0; i < GetChildList()->size(); i++ ) { - pElement = static_cast<XMLParentNode*>((*GetChildList())[ i ]); + XMLParentNode* pElement = static_cast<XMLParentNode*>((*GetChildList())[ i ]); if( pElement->GetNodeType() == XML_NODE_TYPE_ELEMENT ) CheckExportStatus( pElement );//, i); } } @@ -660,18 +658,16 @@ void XMLElement::ChangeLanguageTag( const OString &rValue ) (*m_pAttributes)[ i ]->setValue(rValue); } } - XMLChildNode* pNode = NULL; - XMLElement* pElem = NULL; XMLChildNodeList* pCList = GetChildList(); if( pCList ) { for ( size_t i = 0; i < pCList->size(); i++ ) { - pNode = (*pCList)[ i ]; + XMLChildNode* pNode = (*pCList)[ i ]; if( pNode && pNode->GetNodeType() == XML_NODE_TYPE_ELEMENT ) { - pElem = static_cast< XMLElement* >(pNode); + XMLElement* pElem = static_cast< XMLElement* >(pNode); pElem->ChangeLanguageTag( rValue ); pElem->SetLanguageId(rValue); pElem = NULL; @@ -712,10 +708,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement { if ( pElement->GetChildList()) { - XMLChildNode* pTmp = 0; for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ ) { - pTmp = (*pElement->GetChildList())[ k ]; + XMLChildNode* pTmp = (*pElement->GetChildList())[ k ]; Print( pTmp, rBuffer , false); } } @@ -751,10 +746,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement else { rBuffer.append( ">" ); - XMLChildNode* pTmp = 0; for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ ) { - pTmp = (*pElement->GetChildList())[ k ]; + XMLChildNode* pTmp = (*pElement->GetChildList())[ k ]; Print( pTmp, rBuffer , false); } rBuffer.append( "</" + pElement->GetName() + ">" ); diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx index b8b997931a26..d561fd00412e 100644 --- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx +++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx @@ -255,10 +255,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo const ::com::sun::star::beans::PropertyValues& aProperties ) throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException, std::exception) { - int nHyphenationPos = -1; - int nHyphenationPosAlt = -1; - int nHyphenationPosAltHyph = -1; - int wordlen; int k = 0; PropertyHelper_Hyphenation& rHelper = GetPropHelper(); @@ -269,7 +265,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo HyphenDict *dict = NULL; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW; - CharClass * pCC = NULL; Reference< XHyphenatedWord > xRes; @@ -283,6 +278,10 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo // if we have a hyphenation dictionary matching this locale if (k != -1) { + int nHyphenationPos = -1; + int nHyphenationPosAlt = -1; + int nHyphenationPosAltHyph = -1; + // if this dictinary has not been loaded yet do that if (!aDicts[k].aPtr) { @@ -310,7 +309,7 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo // other wise hyphenate the word with that dictionary dict = aDicts[k].aPtr; eEnc = aDicts[k].eEnc; - pCC = aDicts[k].apCC; + CharClass * pCC = aDicts[k].apCC; // we don't want to work with a default text encoding since following incorrect // results may occur only for specific text and thus may be hard to notice. @@ -342,7 +341,7 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo // now convert word to needed encoding OString encWord(OU2ENC(nTerm,eEnc)); - wordlen = encWord.getLength(); + int wordlen = encWord.getLength(); boost::scoped_array<char> lcword(new char[wordlen + 1]); boost::scoped_array<char> hyphens(new char[wordlen + 5]); diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx index c8d767b05cc1..bb779d249e14 100644 --- a/linguistic/source/dicimp.cxx +++ b/linguistic/source/dicimp.cxx @@ -700,10 +700,9 @@ bool DictionaryNeo::addEntry_Impl(const uno::Reference< XDictionaryEntry > xDicE // look for position to insert entry at // if there is already an entry do not insert the new one sal_Int32 nPos = 0; - bool bFound = false; if (bAddEntry) { - bFound = seekEntry( xDicEntry->getDictionaryWord(), &nPos ); + const bool bFound = seekEntry( xDicEntry->getDictionaryWord(), &nPos ); if (bFound) bAddEntry = false; } diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 41018e3fb6fe..bc31490060de 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -529,7 +529,6 @@ void GrammarCheckingIterator::DequeueAndCheck() uno::Reference< text::XFlatParagraph > xFlatPara; FPEntry aFPEntryItem; OUString aCurDocId; - bool bModified = false; // ---- THREAD SAFE START ---- { ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); @@ -548,7 +547,7 @@ void GrammarCheckingIterator::DequeueAndCheck() OUString aCurTxt( xFlatPara->getText() ); lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex ); - bModified = xFlatPara->isModified(); + const bool bModified = xFlatPara->isModified(); if (!bModified) { // ---- THREAD SAFE START ---- |