Kaydet (Commit) a23f6eb3 authored tarafından Michael Weghorn's avatar Michael Weghorn Kaydeden (comit) Noel Grandin

fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: Ib16e4ecc0e0c43b2c1fb527eb0668a960ae9756e
Reviewed-on: https://gerrit.libreoffice.org/13513Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 36936c25
...@@ -69,11 +69,10 @@ bool AstModule::dump(RegistryKey& rKey) ...@@ -69,11 +69,10 @@ bool AstModule::dump(RegistryKey& rKey)
DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator iter = getIteratorBegin();
DeclList::const_iterator end = getIteratorEnd(); DeclList::const_iterator end = getIteratorEnd();
AstDeclaration* pDecl = NULL;
sal_uInt16 index = 0; sal_uInt16 index = 0;
while ( iter != end ) while ( iter != end )
{ {
pDecl = *iter; AstDeclaration* pDecl = *iter;
if ( pDecl->getNodeType() == NT_const && if ( pDecl->getNodeType() == NT_const &&
pDecl->isInMainfile() ) pDecl->isInMainfile() )
{ {
......
...@@ -37,13 +37,11 @@ AstConstant* AstEnum::checkValue(AstExpression* pExpr) ...@@ -37,13 +37,11 @@ AstConstant* AstEnum::checkValue(AstExpression* pExpr)
{ {
DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator iter = getIteratorBegin();
DeclList::const_iterator end = getIteratorEnd(); DeclList::const_iterator end = getIteratorEnd();
AstConstant* pConst = NULL;
AstDeclaration* pDecl = NULL;
while ( iter != end) while ( iter != end)
{ {
pDecl = *iter; AstDeclaration* pDecl = *iter;
pConst = static_cast<AstConstant*>(pDecl); AstConstant* pConst = static_cast<AstConstant*>(pDecl);
if (pConst->getConstValue()->compare(pExpr)) if (pConst->getConstValue()->compare(pExpr))
return pConst; return pConst;
...@@ -80,11 +78,10 @@ bool AstEnum::dump(RegistryKey& rKey) ...@@ -80,11 +78,10 @@ bool AstEnum::dump(RegistryKey& rKey)
DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator iter = getIteratorBegin();
DeclList::const_iterator end = getIteratorEnd(); DeclList::const_iterator end = getIteratorEnd();
AstDeclaration* pDecl = NULL;
sal_uInt16 index = 0; sal_uInt16 index = 0;
while ( iter != end ) while ( iter != end )
{ {
pDecl = *iter; AstDeclaration* pDecl = *iter;
if ( pDecl->getNodeType() == NT_enum_val ) if ( pDecl->getNodeType() == NT_enum_val )
static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false); static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false);
......
...@@ -60,12 +60,11 @@ bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index) ...@@ -60,12 +60,11 @@ bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index)
{ {
DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator iter = getIteratorBegin();
DeclList::const_iterator end = getIteratorEnd(); DeclList::const_iterator end = getIteratorEnd();
AstDeclaration* pDecl = NULL;
RTParamMode paramMode; RTParamMode paramMode;
sal_uInt16 paramIndex = 0; sal_uInt16 paramIndex = 0;
while ( iter != end ) while ( iter != end )
{ {
pDecl = *iter; AstDeclaration* pDecl = *iter;
if ( pDecl->getNodeType() == NT_parameter ) if ( pDecl->getNodeType() == NT_parameter )
{ {
AstParameter* pParam = static_cast<AstParameter*>(pDecl); AstParameter* pParam = static_cast<AstParameter*>(pDecl);
......
...@@ -121,12 +121,11 @@ bool AstStruct::dump(RegistryKey& rKey) ...@@ -121,12 +121,11 @@ bool AstStruct::dump(RegistryKey& rKey)
{ {
DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator iter = getIteratorBegin();
DeclList::const_iterator end = getIteratorEnd(); DeclList::const_iterator end = getIteratorEnd();
AstDeclaration* pDecl = NULL;
AstMember* pMember = NULL; AstMember* pMember = NULL;
sal_uInt16 index = 0; sal_uInt16 index = 0;
while ( iter != end ) while ( iter != end )
{ {
pDecl = *iter; AstDeclaration* pDecl = *iter;
if ( pDecl->getNodeType() == NT_member ) if ( pDecl->getNodeType() == NT_member )
{ {
pMember = static_cast<AstMember*>(pDecl); pMember = static_cast<AstMember*>(pDecl);
......
...@@ -186,11 +186,11 @@ bool copyFile(const OString* source, const OString& target) ...@@ -186,11 +186,11 @@ bool copyFile(const OString* source, const OString& target)
} }
size_t totalSize = 512; size_t totalSize = 512;
size_t readSize = 0;
char pBuffer[513]; char pBuffer[513];
while ( !feof(pSource) ) while ( !feof(pSource) )
{ {
size_t readSize;
if ( (readSize = fread(pBuffer, 1, totalSize, pSource)) > 0 && !ferror(pSource) ) if ( (readSize = fread(pBuffer, 1, totalSize, pSource)) > 0 && !ferror(pSource) )
{ {
if ( (fwrite(pBuffer, 1, readSize, pTarget)) != readSize || ferror(pTarget) ) if ( (fwrite(pBuffer, 1, readSize, pTarget)) != readSize || ferror(pTarget) )
......
...@@ -103,9 +103,7 @@ bool HelpParser::CreatePO( ...@@ -103,9 +103,7 @@ bool HelpParser::CreatePO(
return false; return false;
} }
XMLHashMap* aXMLStrHM = file->GetStrings(); XMLHashMap* aXMLStrHM = file->GetStrings();
LangHashMap* pElem;
XMLElement* pXMLElement = NULL;
std::vector<OString> order = file->getOrder(); std::vector<OString> order = file->getOrder();
std::vector<OString>::iterator pos; std::vector<OString>::iterator pos;
...@@ -114,9 +112,9 @@ bool HelpParser::CreatePO( ...@@ -114,9 +112,9 @@ bool HelpParser::CreatePO(
for( pos = order.begin(); pos != order.end() ; ++pos ) for( pos = order.begin(); pos != order.end() ; ++pos )
{ {
posm = aXMLStrHM->find( *pos ); posm = aXMLStrHM->find( *pos );
pElem = posm->second; LangHashMap* pElem = posm->second;
pXMLElement = (*pElem)[ "en-US" ]; XMLElement* pXMLElement = (*pElem)[ "en-US" ];
if( pXMLElement != NULL ) if( pXMLElement != NULL )
{ {
...@@ -167,8 +165,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile ...@@ -167,8 +165,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile
{ {
file->Extract(); file->Extract();
XMLHashMap* aXMLStrHM = file->GetStrings(); XMLHashMap* aXMLStrHM = file->GetStrings();
LangHashMap* aLangHM;
static ResData pResData("",""); static ResData pResData("","");
pResData.sResTyp = "help"; pResData.sResTyp = "help";
...@@ -179,7 +176,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile ...@@ -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 for( pos = order.begin(); pos != order.end() ; ++pos ) // Merge every l10n related string in the same order as export
{ {
posm = aXMLStrHM->find( *pos ); posm = aXMLStrHM->find( *pos );
aLangHM = posm->second; LangHashMap* aLangHM = posm->second;
#if OSL_DEBUG_LEVEL > 2 #if OSL_DEBUG_LEVEL > 2
printf("*********************DUMPING HASHMAP***************************************"); printf("*********************DUMPING HASHMAP***************************************");
Dump(aXMLStrHM); Dump(aXMLStrHM);
......
...@@ -89,10 +89,9 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj) ...@@ -89,10 +89,9 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
if( rObj.m_pChildList ) if( rObj.m_pChildList )
{ {
m_pChildList=new XMLChildNodeList(); m_pChildList=new XMLChildNodeList();
XMLChildNode* pNode = NULL;
for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) 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) if( pNode != NULL)
{ {
switch(pNode->GetNodeType()) switch(pNode->GetNodeType())
...@@ -529,12 +528,11 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur ) ...@@ -529,12 +528,11 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur )
{ {
case XML_NODE_TYPE_FILE: case XML_NODE_TYPE_FILE:
{ {
XMLParentNode* pElement;
if( GetChildList()) if( GetChildList())
{ {
for ( size_t i = 0; i < GetChildList()->size(); i++ ) 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); if( pElement->GetNodeType() == XML_NODE_TYPE_ELEMENT ) CheckExportStatus( pElement );//, i);
} }
} }
...@@ -660,18 +658,16 @@ void XMLElement::ChangeLanguageTag( const OString &rValue ) ...@@ -660,18 +658,16 @@ void XMLElement::ChangeLanguageTag( const OString &rValue )
(*m_pAttributes)[ i ]->setValue(rValue); (*m_pAttributes)[ i ]->setValue(rValue);
} }
} }
XMLChildNode* pNode = NULL;
XMLElement* pElem = NULL;
XMLChildNodeList* pCList = GetChildList(); XMLChildNodeList* pCList = GetChildList();
if( pCList ) if( pCList )
{ {
for ( size_t i = 0; i < pCList->size(); i++ ) for ( size_t i = 0; i < pCList->size(); i++ )
{ {
pNode = (*pCList)[ i ]; XMLChildNode* pNode = (*pCList)[ i ];
if( pNode && pNode->GetNodeType() == XML_NODE_TYPE_ELEMENT ) if( pNode && pNode->GetNodeType() == XML_NODE_TYPE_ELEMENT )
{ {
pElem = static_cast< XMLElement* >(pNode); XMLElement* pElem = static_cast< XMLElement* >(pNode);
pElem->ChangeLanguageTag( rValue ); pElem->ChangeLanguageTag( rValue );
pElem->SetLanguageId(rValue); pElem->SetLanguageId(rValue);
pElem = NULL; pElem = NULL;
...@@ -712,10 +708,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement ...@@ -712,10 +708,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement
{ {
if ( pElement->GetChildList()) if ( pElement->GetChildList())
{ {
XMLChildNode* pTmp = 0;
for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ ) for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ )
{ {
pTmp = (*pElement->GetChildList())[ k ]; XMLChildNode* pTmp = (*pElement->GetChildList())[ k ];
Print( pTmp, rBuffer , false); Print( pTmp, rBuffer , false);
} }
} }
...@@ -751,10 +746,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement ...@@ -751,10 +746,9 @@ void XMLElement::Print(XMLNode *pCur, OStringBuffer& rBuffer, bool bRootelement
else else
{ {
rBuffer.append( ">" ); rBuffer.append( ">" );
XMLChildNode* pTmp = 0;
for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ ) for ( size_t k = 0; k < pElement->GetChildList()->size(); k++ )
{ {
pTmp = (*pElement->GetChildList())[ k ]; XMLChildNode* pTmp = (*pElement->GetChildList())[ k ];
Print( pTmp, rBuffer , false); Print( pTmp, rBuffer , false);
} }
rBuffer.append( "</" + pElement->GetName() + ">" ); rBuffer.append( "</" + pElement->GetName() + ">" );
......
...@@ -255,10 +255,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo ...@@ -255,10 +255,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
const ::com::sun::star::beans::PropertyValues& aProperties ) const ::com::sun::star::beans::PropertyValues& aProperties )
throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException, std::exception) 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; int k = 0;
PropertyHelper_Hyphenation& rHelper = GetPropHelper(); PropertyHelper_Hyphenation& rHelper = GetPropHelper();
...@@ -269,7 +265,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo ...@@ -269,7 +265,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
HyphenDict *dict = NULL; HyphenDict *dict = NULL;
rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
CharClass * pCC = NULL;
Reference< XHyphenatedWord > xRes; Reference< XHyphenatedWord > xRes;
...@@ -283,6 +278,10 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo ...@@ -283,6 +278,10 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
// if we have a hyphenation dictionary matching this locale // if we have a hyphenation dictionary matching this locale
if (k != -1) if (k != -1)
{ {
int nHyphenationPos = -1;
int nHyphenationPosAlt = -1;
int nHyphenationPosAltHyph = -1;
// if this dictinary has not been loaded yet do that // if this dictinary has not been loaded yet do that
if (!aDicts[k].aPtr) if (!aDicts[k].aPtr)
{ {
...@@ -310,7 +309,7 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo ...@@ -310,7 +309,7 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
// other wise hyphenate the word with that dictionary // other wise hyphenate the word with that dictionary
dict = aDicts[k].aPtr; dict = aDicts[k].aPtr;
eEnc = aDicts[k].eEnc; 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 // 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. // 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 ...@@ -342,7 +341,7 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
// now convert word to needed encoding // now convert word to needed encoding
OString encWord(OU2ENC(nTerm,eEnc)); 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> lcword(new char[wordlen + 1]);
boost::scoped_array<char> hyphens(new char[wordlen + 5]); boost::scoped_array<char> hyphens(new char[wordlen + 5]);
......
...@@ -700,10 +700,9 @@ bool DictionaryNeo::addEntry_Impl(const uno::Reference< XDictionaryEntry > xDicE ...@@ -700,10 +700,9 @@ bool DictionaryNeo::addEntry_Impl(const uno::Reference< XDictionaryEntry > xDicE
// look for position to insert entry at // look for position to insert entry at
// if there is already an entry do not insert the new one // if there is already an entry do not insert the new one
sal_Int32 nPos = 0; sal_Int32 nPos = 0;
bool bFound = false;
if (bAddEntry) if (bAddEntry)
{ {
bFound = seekEntry( xDicEntry->getDictionaryWord(), &nPos ); const bool bFound = seekEntry( xDicEntry->getDictionaryWord(), &nPos );
if (bFound) if (bFound)
bAddEntry = false; bAddEntry = false;
} }
......
...@@ -529,7 +529,6 @@ void GrammarCheckingIterator::DequeueAndCheck() ...@@ -529,7 +529,6 @@ void GrammarCheckingIterator::DequeueAndCheck()
uno::Reference< text::XFlatParagraph > xFlatPara; uno::Reference< text::XFlatParagraph > xFlatPara;
FPEntry aFPEntryItem; FPEntry aFPEntryItem;
OUString aCurDocId; OUString aCurDocId;
bool bModified = false;
// ---- THREAD SAFE START ---- // ---- THREAD SAFE START ----
{ {
::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
...@@ -548,7 +547,7 @@ void GrammarCheckingIterator::DequeueAndCheck() ...@@ -548,7 +547,7 @@ void GrammarCheckingIterator::DequeueAndCheck()
OUString aCurTxt( xFlatPara->getText() ); OUString aCurTxt( xFlatPara->getText() );
lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex ); lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
bModified = xFlatPara->isModified(); const bool bModified = xFlatPara->isModified();
if (!bModified) if (!bModified)
{ {
// ---- THREAD SAFE START ---- // ---- THREAD SAFE START ----
......
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