idlc/source/astdump.cxx | 3 +-- idlc/source/astenum.cxx | 9 +++------ idlc/source/astoperation.cxx | 3 +-- idlc/source/aststruct.cxx | 3 +-- idlc/source/idlccompile.cxx | 2 +- l10ntools/source/helpmerge.cxx | 13 +++++-------- l10ntools/source/xmlparse.cxx | 18 ++++++------------ lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx | 13 ++++++------- linguistic/source/dicimp.cxx | 3 +-- linguistic/source/gciterator.cxx | 3 +-- 10 files changed, 26 insertions(+), 44 deletions(-)
New commits: commit a23f6eb3ae49dfc326c6e57a8ab95a840c0661d2 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Wed Dec 17 21:16:11 2014 +0100 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 <noelgran...@gmail.com> Tested-by: Noel Grandin <noelgran...@gmail.com> diff --git a/idlc/source/astdump.cxx b/idlc/source/astdump.cxx index 90b182c..e0f786b 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 1f330b1..32f8138 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 5a38c8a..ce67313 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 482ee73..0a85a12 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 45dbfbc..3d4ef7d 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 492f6f7c..7411c55 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 2c376cf..6b2a304 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 b8b9979..d561fd0 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 c8d767b..bb779d2 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 41018e3..bc31490 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 ---- _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits