diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2015-08-22 14:10:55 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-08-23 06:04:49 +0000 |
commit | 9beb2bedc0f65b90cd35f7fa6c9b53ee6729a0c4 (patch) | |
tree | 68c6d690a594433f3ab5ce8ded149d95cbc92b69 /sc/source | |
parent | 90b086e480a83c62edafaf13bdf4a02079a7860c (diff) |
tdf#39440 sc: reduce scope of local variables
This addresses some cppcheck warnings.
Change-Id: Ia7f58c24429310b66f4464d8ba8b4f2e5c6fef38
Reviewed-on: https://gerrit.libreoffice.org/17922
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/interpr5.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/qpro/qproform.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/docshell/dbdocimp.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh4.cxx | 4 |
6 files changed, 15 insertions, 23 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 9df3a901f977..059678281e35 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -1194,7 +1194,6 @@ void ScInterpreter::ScIRR() while (fEps > SCdEpsilon && nItCount < nIterationsMax) { // Newtons method: sp = sPos; // reset stack - double nCount = 0.0; double fNom = 0.0; double fDenom = 0.0; sal_uInt16 nErr = 0; @@ -1202,6 +1201,7 @@ void ScInterpreter::ScIRR() ScValueIterator aValIter(pDok, aRange, mnSubTotalFlags); if (aValIter.GetFirst(fValue, nErr)) { + double nCount = 0.0; fNom += fValue / pow(1.0+x,(double)nCount); fDenom += -nCount * fValue / pow(1.0+x,nCount+1.0); nCount++; diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index 907ce8da921e..6861e93f9969 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -1956,16 +1956,11 @@ double lcl_GetSign(double fValue) bool lcl_CalculateQRdecomposition(ScMatrixRef pMatA, ::std::vector< double>& pVecR, SCSIZE nK, SCSIZE nN) { - double fScale ; - double fEuclid ; - double fFactor ; - double fSignum ; - double fSum ; // ScMatrix matrices are zero based, index access (column,row) for (SCSIZE col = 0; col <nK; col++) { // calculate vector u of the householder transformation - fScale = lcl_GetColumnMaximumNorm(pMatA, col, col, nN); + const double fScale = lcl_GetColumnMaximumNorm(pMatA, col, col, nN); if (fScale == 0.0) { // A is singular @@ -1974,16 +1969,16 @@ bool lcl_CalculateQRdecomposition(ScMatrixRef pMatA, for (SCSIZE row = col; row <nN; row++) pMatA->PutDouble( pMatA->GetDouble(col,row)/fScale, col, row); - fEuclid = lcl_GetColumnEuclideanNorm(pMatA, col, col, nN); - fFactor = 1.0/fEuclid/(fEuclid + fabs(pMatA->GetDouble(col,col))); - fSignum = lcl_GetSign(pMatA->GetDouble(col,col)); + const double fEuclid = lcl_GetColumnEuclideanNorm(pMatA, col, col, nN); + const double fFactor = 1.0/fEuclid/(fEuclid + fabs(pMatA->GetDouble(col,col))); + const double fSignum = lcl_GetSign(pMatA->GetDouble(col,col)); pMatA->PutDouble( pMatA->GetDouble(col,col) + fSignum*fEuclid, col,col); pVecR[col] = -fSignum * fScale * fEuclid; // apply Householder transformation to A for (SCSIZE c=col+1; c<nK; c++) { - fSum =lcl_GetColumnSumProduct(pMatA, col, pMatA, c, col, nN); + const double fSum =lcl_GetColumnSumProduct(pMatA, col, pMatA, c, col, nN); for (SCSIZE row = col; row <nN; row++) pMatA->PutDouble( pMatA->GetDouble(c,row) - fSum * fFactor * pMatA->GetDouble(col,row), c, row); } diff --git a/sc/source/filter/qpro/qproform.cxx b/sc/source/filter/qpro/qproform.cxx index 4a70e875e254..95e4db36549f 100644 --- a/sc/source/filter/qpro/qproform.cxx +++ b/sc/source/filter/qpro/qproform.cxx @@ -189,7 +189,6 @@ ConvErr QProToSc::Convert( const ScTokenArray*& pArray, sal_uInt16 /*nLen*/, con FUNC_TYPE eType; DefTokenId eOc; double nFloatArray[ nBufSize ] = {0}; - double nFloat; const sal_Char* pExtString = 0; aCRD.InitFlags(); @@ -212,6 +211,7 @@ ConvErr QProToSc::Convert( const ScTokenArray*& pArray, sal_uInt16 /*nLen*/, con if( nFmla[ i ] == 0x00 ) { + double nFloat; maIn.ReadDouble( nFloat ); nFloatArray[ nFloatCount ] = nFloat; SAFEDEC_OR_RET(nRef, 8, ConvErrCount); diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx index b7ea4ca7022e..bb48cd0a5f20 100644 --- a/sc/source/ui/docshell/dbdocimp.cxx +++ b/sc/source/ui/docshell/dbdocimp.cxx @@ -152,7 +152,6 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, SCROW nRow = rParam.nRow1; SCCOL nEndCol = nCol; // end of resulting database area SCROW nEndRow = nRow; - long i; bool bDoSelection = false; bool bRealSelection = false; // sal_True if not everything is selected @@ -281,7 +280,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, uno::Sequence<sal_Bool> aColCurr( nColCount ); // currency flag is not in types sal_Int32* pTypeArr = aColTypes.getArray(); sal_Bool* pCurrArr = aColCurr.getArray(); - for (i=0; i<nColCount; i++) + for (long i=0; i<nColCount; i++) { pTypeArr[i] = xMeta->getColumnType( i+1 ); pCurrArr[i] = xMeta->isCurrency( i+1 ); @@ -290,7 +289,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, if ( !bAddrInsert ) // read column names { nCol = rParam.nCol1; - for (i=0; i<nColCount; i++) + for (long i=0; i<nColCount; i++) { pImportDoc->SetString( nCol, nRow, nTab, xMeta->getColumnLabel( i+1 ) ); @@ -342,7 +341,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, if ( ValidRow(nRow) ) { nCol = rParam.nCol1; - for (i=0; i<nColCount; i++) + for (long i=0; i<nColCount; i++) { ScDatabaseDocUtil::PutData( pImportDoc, nCol, nRow, nTab, xRow, i+1, pTypeArr[i], pCurrArr[i] ); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 86671ecf931e..4ba25063eb3d 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -451,12 +451,12 @@ bool ScDocFunc::DetectiveRefresh( bool bAutomatic ) bool bDone = false; ScDocument& rDoc = rDocShell.GetDocument(); - bool bUndo (rDoc.IsUndoEnabled()); ScDetOpList* pList = rDoc.GetDetOpList(); if ( pList && pList->Count() ) { rDocShell.MakeDrawLayer(); ScDrawLayer* pModel = rDoc.GetDrawLayer(); + const bool bUndo (rDoc.IsUndoEnabled()); if (bUndo) pModel->BeginCalcUndo(false); @@ -4052,8 +4052,6 @@ bool ScDocFunc::EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark, SCROW nEndRow = rRange.aEnd.Row(); SCTAB nEndTab = rRange.aEnd.Tab(); - bool bUndo(rDoc.IsUndoEnabled()); - ScMarkData aMark; if (pTabMark) aMark = *pTabMark; @@ -4070,6 +4068,7 @@ bool ScDocFunc::EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark, ScDocument* pUndoDoc = NULL; + const bool bUndo(rDoc.IsUndoEnabled()); if (bUndo) { //! auch bei Undo selektierte Tabellen beruecksichtigen @@ -5167,8 +5166,6 @@ bool ScDocFunc::ResizeMatrix( const ScRange& rOldRange, const ScAddress& rNewEnd SCROW nStartRow = rOldRange.aStart.Row(); SCTAB nTab = rOldRange.aStart.Tab(); - bool bUndo(rDoc.IsUndoEnabled()); - bool bRet = false; OUString aFormula; @@ -5176,6 +5173,7 @@ bool ScDocFunc::ResizeMatrix( const ScRange& rOldRange, const ScAddress& rNewEnd if ( aFormula.startsWith("{") && aFormula.endsWith("}") ) { OUString aUndo = ScGlobal::GetRscString( STR_UNDO_RESIZEMATRIX ); + bool bUndo(rDoc.IsUndoEnabled()); if (bUndo) rDocShell.GetUndoManager()->EnterListAction( aUndo, aUndo ); diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index a2225f564f50..b422a5150163 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -1366,7 +1366,6 @@ void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint ) void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages ) { - bool bUndo(aDocument.IsUndoEnabled()); OUString aStyleName = aDocument.GetPageStyle( nTab ); ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE ); @@ -1376,6 +1375,7 @@ void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages ScDocShellModificator aModificator( *this ); SfxItemSet& rSet = pStyleSheet->GetItemSet(); + const bool bUndo(aDocument.IsUndoEnabled()); if (bUndo) { sal_uInt16 nOldScale = static_cast<const SfxUInt16Item&>(rSet.Get(ATTR_PAGE_SCALE)).GetValue(); @@ -1532,7 +1532,6 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller, } else if ( pReqArgs == NULL ) { - bool bUndo(aDocument.IsUndoEnabled()); OUString aOldName = aDocument.GetPageStyle( nCurTab ); ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); SfxStyleSheetBase* pStyleSheet @@ -1543,6 +1542,7 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller, if ( pStyleSheet ) { ScStyleSaveData aOldData; + const bool bUndo(aDocument.IsUndoEnabled()); if (bUndo) aOldData.InitFromStyle( pStyleSheet ); |