summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-15 09:25:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-15 20:59:31 +0200
commit61d8db6b1a2026a29f61eaa691beb3c6cf05de5c (patch)
treefc81eda81cf811256290c3e564166ef217f8268e /sc/source/core
parent7baa60a5e9a8c48829f47db8cd98d0f05a30e235 (diff)
loplugin:buriedassign in sc
Change-Id: I9b4146c4e8814a36c7bfcd4c31f913c8412320e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92244 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/column.cxx12
-rw-r--r--sc/source/core/data/column3.cxx13
-rw-r--r--sc/source/core/data/dociter.cxx5
-rw-r--r--sc/source/core/data/documen4.cxx13
-rw-r--r--sc/source/core/data/formulacell.cxx53
-rw-r--r--sc/source/core/data/global2.cxx4
-rw-r--r--sc/source/core/data/table6.cxx207
-rw-r--r--sc/source/core/data/validat.cxx41
-rw-r--r--sc/source/core/tool/chartpos.cxx24
-rw-r--r--sc/source/core/tool/chgtrack.cxx31
-rw-r--r--sc/source/core/tool/compiler.cxx20
-rw-r--r--sc/source/core/tool/interpr1.cxx4
-rw-r--r--sc/source/core/tool/interpr4.cxx64
-rw-r--r--sc/source/core/tool/token.cxx63
14 files changed, 313 insertions, 241 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 9388e01ee1f0..a223352b8dd3 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -627,9 +627,11 @@ const ScStyleSheet* ScColumn::GetSelectionStyle( const ScMarkData& rMark, bool&
ScAttrIterator aAttrIter( pAttrArray.get(), nTop, nBottom, pDocument->GetDefPattern() );
SCROW nRow;
SCROW nDummy;
- const ScPatternAttr* pPattern;
- while (bEqual && ( pPattern = aAttrIter.Next( nRow, nDummy ) ) != nullptr)
+ while (bEqual)
{
+ const ScPatternAttr* pPattern = aAttrIter.Next( nRow, nDummy );
+ if (!pPattern)
+ break;
pNewStyle = pPattern->GetStyleSheet();
rFound = true;
if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
@@ -653,9 +655,11 @@ const ScStyleSheet* ScColumn::GetAreaStyle( bool& rFound, SCROW nRow1, SCROW nRo
ScAttrIterator aAttrIter( pAttrArray.get(), nRow1, nRow2, GetDoc()->GetDefPattern() );
SCROW nRow;
SCROW nDummy;
- const ScPatternAttr* pPattern;
- while (bEqual && ( pPattern = aAttrIter.Next( nRow, nDummy ) ) != nullptr)
+ while (bEqual)
{
+ const ScPatternAttr* pPattern = aAttrIter.Next( nRow, nDummy );
+ if (!pPattern)
+ break;
pNewStyle = pPattern->GetStyleSheet();
rFound = true;
if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 2f3869db93c0..88ed96df0f3c 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1965,16 +1965,17 @@ bool ScColumn::ParseString(
sal_uInt32 nIndex = 0;
sal_uInt32 nOldIndex = 0;
SvNumFormatType eNumFormatType = SvNumFormatType::ALL;
- sal_Unicode cFirstChar;
if (!aParam.mpNumFormatter)
aParam.mpNumFormatter = GetDoc()->GetFormatTable();
+ sal_Unicode cFirstChar = 0; // Text
nIndex = nOldIndex = GetNumberFormat( GetDoc()->GetNonThreadedContext(), nRow );
- if ( rString.getLength() > 1
- && (eNumFormatType = aParam.mpNumFormatter->GetType(nIndex)) != SvNumFormatType::TEXT )
- cFirstChar = rString[0];
- else
- cFirstChar = 0; // Text
+ if ( rString.getLength() > 1 )
+ {
+ eNumFormatType = aParam.mpNumFormatter->GetType(nIndex);
+ if ( eNumFormatType != SvNumFormatType::TEXT )
+ cFirstChar = rString[0];
+ }
svl::SharedStringPool& rPool = GetDoc()->GetSharedStringPool();
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 604cbbf361b0..85be65c5c17d 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1312,8 +1312,11 @@ bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
nFoundCol = GetCol();
nFoundRow = GetRow();
aPosSave = maCurPos;
+ if (IsEqualConditionFulfilled())
+ break;
+ bNext = GetNext();
}
- while ( !IsEqualConditionFulfilled() && (bNext = GetNext()));
+ while (bNext);
// There may be no pNext but equal condition fulfilled if regular
// expressions are involved. Keep the found entry and proceed.
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 871d0cba34cc..bbed307d5cc6 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -489,10 +489,12 @@ bool ScDocument::MarkUsedExternalReferences( const ScTokenArray& rArr, const ScA
ScExternalRefManager* pRefMgr = nullptr;
formula::FormulaTokenArrayPlainIterator aIter( rArr );
- formula::FormulaToken* t = nullptr;
bool bAllMarked = false;
- while (!bAllMarked && (t = aIter.GetNextReferenceOrName()) != nullptr)
+ while (!bAllMarked)
{
+ formula::FormulaToken* t = aIter.GetNextReferenceOrName();
+ if (!t)
+ break;
if (t->IsExternalRef())
{
if (!pRefMgr)
@@ -632,9 +634,10 @@ double ScDocument::RoundValueAsShown( double fVal, sal_uInt32 nFormat, const ScI
{
const SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : GetFormatTable();
const SvNumberformat* pFormat = pFormatter->GetEntry( nFormat );
- SvNumFormatType nType;
- if (pFormat && (nType = pFormat->GetMaskedType()) != SvNumFormatType::DATE
- && nType != SvNumFormatType::TIME && nType != SvNumFormatType::DATETIME )
+ if (!pFormat)
+ return fVal;
+ SvNumFormatType nType = pFormat->GetMaskedType();
+ if (nType != SvNumFormatType::DATE && nType != SvNumFormatType::TIME && nType != SvNumFormatType::DATETIME )
{
short nPrecision;
if ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 90f7c70b01e7..328b881b516c 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -881,9 +881,11 @@ ScFormulaCell::ScFormulaCell(const ScFormulaCell& rCell, ScDocument& rDoc, const
if( !bCompile )
{ // Name references with references and ColRowNames
formula::FormulaTokenArrayPlainIterator aIter(*pCode);
- formula::FormulaToken* t;
- while ( ( t = aIter.GetNextReferenceOrName() ) != nullptr && !bCompile )
+ for (;;)
{
+ formula::FormulaToken* t = aIter.GetNextReferenceOrName();
+ if (!t || bCompile)
+ break;
if ( t->IsExternalRef() )
{
// External name, cell, and area references.
@@ -1094,15 +1096,17 @@ void ScFormulaCell::GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows )
{
MaybeInterpret();
- const ScMatrix* pMat = nullptr;
- if (pCode->GetCodeError() == FormulaError::NONE && aResult.GetType() == svMatrixCell &&
- ((pMat = aResult.GetToken()->GetMatrix()) != nullptr))
- pMat->GetDimensions( rCols, rRows );
- else
+ if (pCode->GetCodeError() == FormulaError::NONE && aResult.GetType() == svMatrixCell)
{
- rCols = 0;
- rRows = 0;
+ const ScMatrix* pMat = aResult.GetToken()->GetMatrix();
+ if (pMat)
+ {
+ pMat->GetDimensions( rCols, rRows );
+ return;
+ }
}
+ rCols = 0;
+ rRows = 0;
}
void ScFormulaCell::ResetDirty() { bDirty = bTableOpDirty = mbPostponedDirty = false; }
@@ -1699,14 +1703,17 @@ bool ScFormulaCell::Interpret(SCROW nStartOffset, SCROW nEndOffset)
* added above with rRecursionHelper.Insert() should always
* be 'this', shouldn't it? */
ScFormulaCell* pLastCell = nullptr;
- if (rRecursionHelper.GetList().size() > 1 &&
- ((pLastCell = rRecursionHelper.GetList().back().pCell) != this))
+ if (rRecursionHelper.GetList().size() > 1)
{
- pDocument->IncInterpretLevel();
- ScInterpreterContextGetterGuard aContextGetterGuard(*pDocument, pDocument->GetFormatTable());
- pLastCell->InterpretTail(
- *aContextGetterGuard.GetInterpreterContext(), SCITP_CLOSE_ITERATION_CIRCLE);
- pDocument->DecInterpretLevel();
+ pLastCell = rRecursionHelper.GetList().back().pCell;
+ if (pLastCell != this)
+ {
+ pDocument->IncInterpretLevel();
+ ScInterpreterContextGetterGuard aContextGetterGuard(*pDocument, pDocument->GetFormatTable());
+ pLastCell->InterpretTail(
+ *aContextGetterGuard.GetInterpreterContext(), SCITP_CLOSE_ITERATION_CIRCLE);
+ pDocument->DecInterpretLevel();
+ }
}
// Start at 1, init things.
rRecursionHelper.StartIteration();
@@ -2039,8 +2046,8 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa
const SvNumFormatType nRetType = pInterpreter->GetRetFormatType();
if (nRetType == SvNumFormatType::LOGICAL)
{
- double fVal;
- if ((fVal = aNewResult.GetDouble()) != 1.0 && fVal != 0.0)
+ double fVal = aNewResult.GetDouble();
+ if (fVal != 1.0 && fVal != 0.0)
bForceNumberFormat = false;
else
{
@@ -2112,10 +2119,14 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa
bSetFormat = false;
nFormatType = nOldFormatType; // that? or number?
}
- else if ((fVal = aNewResult.GetDouble()) != 1.0 && fVal != 0.0)
+ else
{
- bSetFormat = false;
- nFormatType = SvNumFormatType::NUMBER;
+ fVal = aNewResult.GetDouble();
+ if (fVal != 1.0 && fVal != 0.0)
+ {
+ bSetFormat = false;
+ nFormatType = SvNumFormatType::NUMBER;
+ }
}
}
}
diff --git a/sc/source/core/data/global2.cxx b/sc/source/core/data/global2.cxx
index 95c6f81dffbc..0f10debc2aa1 100644
--- a/sc/source/core/data/global2.cxx
+++ b/sc/source/core/data/global2.cxx
@@ -421,8 +421,8 @@ Label_fallback_to_unambiguous:
// Decimal and group separator 0 => only integer and possibly exponent,
// stops at first non-digit non-sign.
fValue = ::rtl::math::stringToDouble( rStr, 0, 0, &eStatus, &nParseEnd);
- sal_Int32 nLen;
- if (eStatus == rtl_math_ConversionStatus_Ok && nParseEnd < (nLen = rStr.getLength()))
+ sal_Int32 nLen = rStr.getLength();
+ if (eStatus == rtl_math_ConversionStatus_Ok && nParseEnd < nLen)
{
// Not at string end, check for trailing blanks or switch to date or
// time parsing or bail out.
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 63eab0850af8..4769a78b2a77 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -151,119 +151,130 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
return bFound;
}
+ if (!bFound)
+ return false;
+ if ( rSearchItem.GetCommand() != SvxSearchCmd::REPLACE
+ && rSearchItem.GetCommand() != SvxSearchCmd::REPLACE_ALL )
+ return bFound;
+
+ if (!IsBlockEditable(nCol, nRow, nCol, nRow))
+ return bFound;
+
ScMatrixMode cMatrixFlag = ScMatrixMode::NONE;
- if ( bFound &&
- ( (rSearchItem.GetCommand() == SvxSearchCmd::REPLACE)
- ||(rSearchItem.GetCommand() == SvxSearchCmd::REPLACE_ALL) ) &&
- // Don't split the matrix, only replace Matrix formulas
- !( (eCellType == CELLTYPE_FORMULA &&
- ((cMatrixFlag = aCell.mpFormula->GetMatrixFlag()) == ScMatrixMode::Reference))
- // No UndoDoc => Matrix not restorable => don't replace
- || (cMatrixFlag != ScMatrixMode::NONE && !pUndoDoc) ) &&
- IsBlockEditable(nCol, nRow, nCol, nRow)
- )
+
+ // Don't split the matrix, only replace Matrix formulas
+ if (eCellType == CELLTYPE_FORMULA)
+ {
+ cMatrixFlag = aCell.mpFormula->GetMatrixFlag();
+ if(cMatrixFlag == ScMatrixMode::Reference)
+ return bFound;
+ }
+ // No UndoDoc => Matrix not restorable => don't replace
+ if (cMatrixFlag != ScMatrixMode::NONE && !pUndoDoc)
+ return bFound;
+
+ if ( cMatrixFlag == ScMatrixMode::NONE && rSearchItem.GetCommand() == SvxSearchCmd::REPLACE )
+ rUndoStr = aString;
+ else if (pUndoDoc)
+ {
+ ScAddress aAdr( nCol, nRow, nTab );
+ aCell.commit(*pUndoDoc, aAdr);
+ }
+
+ bool bRepeat = !rSearchItem.GetWordOnly();
+ do
{
- if ( cMatrixFlag == ScMatrixMode::NONE && rSearchItem.GetCommand() == SvxSearchCmd::REPLACE )
- rUndoStr = aString;
- else if (pUndoDoc)
+ // don't continue search if the found text is empty,
+ // otherwise it would never stop (#35410#)
+ if ( nEnd < nStart )
+ bRepeat = false;
+
+ OUString sReplStr = rSearchItem.GetReplaceString();
+ if (rSearchItem.GetRegExp())
{
- ScAddress aAdr( nCol, nRow, nTab );
- aCell.commit(*pUndoDoc, aAdr);
+ pSearchText->ReplaceBackReferences( sReplStr, aString, aSearchResult );
+ OUStringBuffer aStrBuffer(aString);
+ aStrBuffer.remove(nStart, nEnd-nStart+1);
+ aStrBuffer.insert(nStart, sReplStr);
+ aString = aStrBuffer.makeStringAndClear();
}
- bool bRepeat = !rSearchItem.GetWordOnly();
- do
+ else
{
- // don't continue search if the found text is empty,
- // otherwise it would never stop (#35410#)
- if ( nEnd < nStart )
- bRepeat = false;
+ OUStringBuffer aStrBuffer(aString);
+ aStrBuffer.remove(nStart, nEnd-nStart+1);
+ aStrBuffer.insert(nStart, rSearchItem.GetReplaceString());
+ aString = aStrBuffer.makeStringAndClear();
+ }
- OUString sReplStr = rSearchItem.GetReplaceString();
- if (rSearchItem.GetRegExp())
- {
- pSearchText->ReplaceBackReferences( sReplStr, aString, aSearchResult );
- OUStringBuffer aStrBuffer(aString);
- aStrBuffer.remove(nStart, nEnd-nStart+1);
- aStrBuffer.insert(nStart, sReplStr);
- aString = aStrBuffer.makeStringAndClear();
- }
- else
- {
- OUStringBuffer aStrBuffer(aString);
- aStrBuffer.remove(nStart, nEnd-nStart+1);
- aStrBuffer.insert(nStart, rSearchItem.GetReplaceString());
- aString = aStrBuffer.makeStringAndClear();
- }
+ // Adjust index
+ if (bDoBack)
+ {
+ nEnd = nStart;
+ nStart = 0;
+ }
+ else
+ {
+ nStart = nStart + sReplStr.getLength();
+ nEnd = aString.getLength();
+ }
- // Adjust index
- if (bDoBack)
+ // continue search ?
+ if (bRepeat)
+ {
+ if ( rSearchItem.GetCommand() != SvxSearchCmd::REPLACE_ALL || nStart >= nEnd )
+ bRepeat = false;
+ else if (bDoBack)
{
- nEnd = nStart;
- nStart = 0;
+ sal_Int32 nTemp=nStart; nStart=nEnd; nEnd=nTemp;
+ bRepeat = pSearchText->SearchBackward(aString, &nStart, &nEnd, &aSearchResult);
+ // change results to definition before 614:
+ --nEnd;
}
else
{
- nStart = nStart + sReplStr.getLength();
- nEnd = aString.getLength();
- }
-
- // continue search ?
- if (bRepeat)
- {
- if ( rSearchItem.GetCommand() != SvxSearchCmd::REPLACE_ALL || nStart >= nEnd )
- bRepeat = false;
- else if (bDoBack)
- {
- sal_Int32 nTemp=nStart; nStart=nEnd; nEnd=nTemp;
- bRepeat = pSearchText->SearchBackward(aString, &nStart, &nEnd, &aSearchResult);
- // change results to definition before 614:
- --nEnd;
- }
- else
- {
- bRepeat = pSearchText->SearchForward(aString, &nStart, &nEnd, &aSearchResult);
- // change results to definition before 614:
- --nEnd;
- }
+ bRepeat = pSearchText->SearchForward(aString, &nStart, &nEnd, &aSearchResult);
+ // change results to definition before 614:
+ --nEnd;
}
}
- while (bRepeat);
- if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
- {
- // NB: rich text format is lost.
- // This is also true of Cells.
- if (pNote)
- pNote->SetText( ScAddress( nCol, nRow, nTab ), aString );
- }
- else if ( cMatrixFlag != ScMatrixMode::NONE )
- { // don't split Matrix
- if ( aString.getLength() > 2 )
- { // remove {} here so that "{=" can be replaced by "{=..."
- if ( aString[ aString.getLength()-1 ] == '}' )
- aString = aString.copy( 0, aString.getLength()-1 );
- if ( aString[0] == '{' )
- aString = aString.copy( 1 );
- }
- ScAddress aAdr( nCol, nRow, nTab );
- ScFormulaCell* pFCell = new ScFormulaCell( pDocument, aAdr,
- aString, pDocument->GetGrammar(), cMatrixFlag );
- SCCOL nMatCols;
- SCROW nMatRows;
- aCell.mpFormula->GetMatColsRows(nMatCols, nMatRows);
- pFCell->SetMatColsRows( nMatCols, nMatRows );
- aCol[nCol].SetFormulaCell(nRow, pFCell);
- }
- else if ( bMultiLine && aString.indexOf('\n') != -1 )
- {
- ScFieldEditEngine& rEngine = pDocument->GetEditEngine();
- rEngine.SetTextCurrentDefaults(aString);
- SetEditText(nCol, nRow, rEngine.CreateTextObject());
+ }
+ while (bRepeat);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ {
+ // NB: rich text format is lost.
+ // This is also true of Cells.
+ if (pNote)
+ pNote->SetText( ScAddress( nCol, nRow, nTab ), aString );
+ }
+ else if ( cMatrixFlag != ScMatrixMode::NONE )
+ { // don't split Matrix
+ if ( aString.getLength() > 2 )
+ { // remove {} here so that "{=" can be replaced by "{=..."
+ if ( aString[ aString.getLength()-1 ] == '}' )
+ aString = aString.copy( 0, aString.getLength()-1 );
+ if ( aString[0] == '{' )
+ aString = aString.copy( 1 );
}
- else
- aCol[nCol].SetString(nRow, nTab, aString, pDocument->GetAddressConvention());
- // pCell is invalid now (deleted)
- aCol[nCol].InitBlockPosition( rBlockPos ); // invalidate also the cached position
+ ScAddress aAdr( nCol, nRow, nTab );
+ ScFormulaCell* pFCell = new ScFormulaCell( pDocument, aAdr,
+ aString, pDocument->GetGrammar(), cMatrixFlag );
+ SCCOL nMatCols;
+ SCROW nMatRows;
+ aCell.mpFormula->GetMatColsRows(nMatCols, nMatRows);
+ pFCell->SetMatColsRows( nMatCols, nMatRows );
+ aCol[nCol].SetFormulaCell(nRow, pFCell);
+ }
+ else if ( bMultiLine && aString.indexOf('\n') != -1 )
+ {
+ ScFieldEditEngine& rEngine = pDocument->GetEditEngine();
+ rEngine.SetTextCurrentDefaults(aString);
+ SetEditText(nCol, nRow, rEngine.CreateTextObject());
}
+ else
+ aCol[nCol].SetString(nRow, nTab, aString, pDocument->GetAddressConvention());
+ // pCell is invalid now (deleted)
+ aCol[nCol].InitBlockPosition( rBlockPos ); // invalidate also the cached position
+
return bFound;
}
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 056fd3eb6547..e2921aaf7368 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -732,32 +732,35 @@ bool ScValidationData::GetSelectionFromFormula(
ScRange aRange;
ScTokenArray* pArr = const_cast<ScTokenArray*>(&rTokArr);
- formula::FormulaTokenArrayPlainIterator aIter(*pArr);
- formula::FormulaToken* t = nullptr;
- if (pArr->GetLen() == 1 && (t = aIter.GetNextReferenceOrName()) != nullptr)
+ if (pArr->GetLen() == 1)
{
- OpCode eOpCode = t->GetOpCode();
- if (eOpCode == ocDBArea || eOpCode == ocTableRef)
+ formula::FormulaTokenArrayPlainIterator aIter(*pArr);
+ formula::FormulaToken* t = aIter.GetNextReferenceOrName();
+ if (t)
{
- if (const ScDBData* pDBData = pDocument->GetDBCollection()->getNamedDBs().findByIndex(t->GetIndex()))
+ OpCode eOpCode = t->GetOpCode();
+ if (eOpCode == ocDBArea || eOpCode == ocTableRef)
{
- pDBData->GetArea(aRange);
- bRef = true;
+ if (const ScDBData* pDBData = pDocument->GetDBCollection()->getNamedDBs().findByIndex(t->GetIndex()))
+ {
+ pDBData->GetArea(aRange);
+ bRef = true;
+ }
}
- }
- else if (eOpCode == ocName)
- {
- const ScRangeData* pName = pDocument->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
- if (pName && pName->IsReference(aRange))
+ else if (eOpCode == ocName)
{
- bRef = true;
+ const ScRangeData* pName = pDocument->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
+ if (pName && pName->IsReference(aRange))
+ {
+ bRef = true;
+ }
}
- }
- else if (t->GetType() != svIndex)
- {
- if (pArr->IsValidReference(aRange, rPos))
+ else if (t->GetType() != svIndex)
{
- bRef = true;
+ if (pArr->IsValidReference(aRange, rPos))
+ {
+ bRef = true;
+ }
}
}
}
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 6448fa3d8d91..89326661f319 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -204,10 +204,14 @@ void ScChartPositioner::GlueState()
else
*p = CellState::Free;
}
- if ( bGlue && *(p = (pA.get() + (((static_cast<sal_uLong>(nCol)+1) * nR) - 1))) == CellState::Free )
- { // mark column as totally unused
- *p = CellState::Glue;
- bGlueCols = true; // one unused column at least
+ if ( bGlue )
+ {
+ p = pA.get() + (((static_cast<sal_uLong>(nCol)+1) * nR) - 1);
+ if (*p == CellState::Free)
+ { // mark column as totally unused
+ *p = CellState::Glue;
+ bGlueCols = true; // one unused column at least
+ }
}
}
@@ -227,10 +231,14 @@ void ScChartPositioner::GlueState()
else
*p = CellState::Free;
}
- if ( bGlue && *(p = (pA.get() + (((static_cast<sal_uLong>(nC)-1) * nR) + nRow))) == CellState::Free )
- { // mark row as totally unused
- *p = CellState::Glue;
- bGlueRows = true; // one unused row at least
+ if ( bGlue )
+ {
+ p = pA.get() + (((static_cast<sal_uLong>(nC)-1) * nR) + nRow);
+ if (*p == CellState::Free )
+ { // mark row as totally unused
+ *p = CellState::Glue;
+ bGlueRows = true; // one unused row at least
+ }
}
}
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index a29e21d244c0..a6524f95da7d 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -370,9 +370,8 @@ bool ScChangeAction::IsDeletedInDelType( ScChangeActionType eDelType ) const
}
while ( pL )
{
- ScChangeAction* p;
- if ( (p = pL->GetAction()) != nullptr &&
- (p->GetType() == eDelType || p->GetType() == eInsType) )
+ ScChangeAction* p = pL->GetAction();
+ if ( p != nullptr && (p->GetType() == eDelType || p->GetType() == eInsType) )
return true;
pL = pL->GetNext();
}
@@ -3654,9 +3653,13 @@ void ScChangeTrack::UpdateReference( ScChangeAction** ppFirstAction,
// Split up the ContentChain
ScChangeActionContent *pHere, *pTmp;
pHere = static_cast<ScChangeActionContent*>(p);
- while ( (pTmp = pHere->GetPrevContent()) != nullptr &&
- pTmp->GetActionNumber() > nEndLastCut )
+ for (;;)
+ {
+ pTmp = pHere->GetPrevContent();
+ if (!pTmp || pTmp->GetActionNumber() <= nEndLastCut)
+ break;
pHere = pTmp;
+ }
if ( pTmp )
{ // Becomes TopContent of the Move
pTmp->SetNextContent( nullptr );
@@ -3888,9 +3891,14 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
// if this Delete is at the top of a Row
ScChangeActionType eType = pDel->GetType();
ScChangeAction* p = pDel;
- while ( (p = p->GetPrev()) != nullptr && p->GetType() == eType &&
- !static_cast<ScChangeActionDel*>(p)->IsTopDelete() )
+ for (;;)
+ {
+ p = p->GetPrev();
+ if (!p || p->GetType() != eType ||
+ static_cast<ScChangeActionDel*>(p)->IsTopDelete() )
+ break;
rMap.insert( ::std::make_pair( p->GetActionNumber(), p ) );
+ }
// delete this in the map too
rMap.insert( ::std::make_pair( pAct->GetActionNumber(), pAct ) );
}
@@ -4030,10 +4038,13 @@ bool ScChangeTrack::SelectContent( ScChangeAction* pAct, bool bOldest )
if ( bOldest )
{
pContent = pContent->GetTopContent();
- ScChangeActionContent* pPrevContent;
- while ( (pPrevContent = pContent->GetPrevContent()) != nullptr &&
- pPrevContent->IsVirgin() )
+ for (;;)
+ {
+ ScChangeActionContent* pPrevContent = pContent->GetPrevContent();
+ if ( !pPrevContent || !pPrevContent->IsVirgin() )
+ break;
pContent = pPrevContent;
+ }
}
if ( !pContent->IsClickable() )
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 0c1e9e5d07bb..8217c6a411e8 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2954,8 +2954,10 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
bFound = true;
}
}
- OpCode eOp;
- if (bFound && ((eOp = maRawToken.GetOpCode()) == ocSub || eOp == ocNegSub))
+ if (!bFound)
+ return false;
+ OpCode eOp = maRawToken.GetOpCode();
+ if (eOp == ocSub || eOp == ocNegSub)
{
bool bShouldBeNegSub =
(eLastOp == ocOpen || eLastOp == ocSep || eLastOp == ocNegSub ||
@@ -4026,12 +4028,14 @@ void ScCompiler::AutoCorrectParsedSymbol()
{
OUString aSymbol( aCorrectedSymbol );
OUString aDoc;
- sal_Int32 nPosition;
- if ( aSymbol[0] == '\''
- && ((nPosition = aSymbol.indexOf( "'#" )) != -1) )
- { // Split off 'Doc'#, may be d:\... or whatever
- aDoc = aSymbol.copy(0, nPosition + 2);
- aSymbol = aSymbol.copy(nPosition + 2);
+ if ( aSymbol[0] == '\'' )
+ {
+ sal_Int32 nPosition = aSymbol.indexOf( "'#" );
+ if (nPosition != -1)
+ { // Split off 'Doc'#, may be d:\... or whatever
+ aDoc = aSymbol.copy(0, nPosition + 2);
+ aSymbol = aSymbol.copy(nPosition + 2);
+ }
}
sal_Int32 nRefs = comphelper::string::getTokenCount(aSymbol, ':');
bool bColons;
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 4daf1afaa169..8f54c25d258b 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8180,8 +8180,8 @@ void ScInterpreter::ScIndirect()
// Anything else that resolves to one reference could be added
// here, but we don't want to compile every arbitrary string. This
// is already nasty enough...
- sal_Int32 nIndex = 0;
- if ((nIndex = sRefStr.indexOf('[')) >= 0 && sRefStr.indexOf(']',nIndex+1) > nIndex)
+ sal_Int32 nIndex = sRefStr.indexOf('[');
+ if (nIndex >= 0 && sRefStr.indexOf(']',nIndex+1) > nIndex)
{
do
{
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index f1506f60adeb..2be1e335a40e 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -3711,19 +3711,22 @@ void ScInterpreter::ScColRowNameAuto()
if (aAbs.aEnd.Row() > nRow2)
aAbs.aEnd.SetRow(nRow2);
SCROW nMyRow;
- if ( aPos.Col() == nStartCol
- && nStartRow <= (nMyRow = aPos.Row()) && nMyRow <= aAbs.aEnd.Row())
- { //Formula in the same column and within the range
- if ( nMyRow == nStartRow )
- { // take the rest under the name
- nStartRow++;
- if ( nStartRow > pDok->MaxRow() )
- nStartRow = pDok->MaxRow();
- aAbs.aStart.SetRow(nStartRow);
- }
- else
- { // below the name to the formula cell
- aAbs.aEnd.SetRow(nMyRow - 1);
+ if ( aPos.Col() == nStartCol )
+ {
+ nMyRow = aPos.Row();
+ if ( nStartRow <= nMyRow && nMyRow <= aAbs.aEnd.Row())
+ { //Formula in the same column and within the range
+ if ( nMyRow == nStartRow )
+ { // take the rest under the name
+ nStartRow++;
+ if ( nStartRow > pDok->MaxRow() )
+ nStartRow = pDok->MaxRow();
+ aAbs.aStart.SetRow(nStartRow);
+ }
+ else
+ { // below the name to the formula cell
+ aAbs.aEnd.SetRow(nMyRow - 1);
+ }
}
}
}
@@ -3734,19 +3737,22 @@ void ScInterpreter::ScColRowNameAuto()
if (aAbs.aEnd.Col() > nCol2)
aAbs.aEnd.SetCol(nCol2);
SCCOL nMyCol;
- if ( aPos.Row() == nStartRow
- && nStartCol <= (nMyCol = aPos.Col()) && nMyCol <= aAbs.aEnd.Col())
- { //Formula in the same column and within the range
- if ( nMyCol == nStartCol )
- { // take the rest under the name
- nStartCol++;
- if ( nStartCol > pDok->MaxCol() )
- nStartCol = pDok->MaxCol();
- aAbs.aStart.SetCol(nStartCol);
- }
- else
- { // below the name to the formula cell
- aAbs.aEnd.SetCol(nMyCol - 1);
+ if ( aPos.Row() == nStartRow )
+ {
+ nMyCol = aPos.Col();
+ if (nStartCol <= nMyCol && nMyCol <= aAbs.aEnd.Col())
+ { //Formula in the same column and within the range
+ if ( nMyCol == nStartCol )
+ { // take the rest under the name
+ nStartCol++;
+ if ( nStartCol > pDok->MaxCol() )
+ nStartCol = pDok->MaxCol();
+ aAbs.aStart.SetCol(nStartCol);
+ }
+ else
+ { // below the name to the formula cell
+ aAbs.aEnd.SetCol(nMyCol - 1);
+ }
}
}
}
@@ -3966,9 +3972,11 @@ StackVar ScInterpreter::Interpret()
OpCode eOp = ocNone;
aCode.Reset();
- while( ( pCur = aCode.Next() ) != nullptr
- && (nGlobalError == FormulaError::NONE || nErrorFunction <= nErrorFunctionCount) )
+ for (;;)
{
+ pCur = aCode.Next();
+ if (!pCur || (nGlobalError != FormulaError::NONE && nErrorFunction > nErrorFunctionCount) )
+ break;
eOp = pCur->GetOpCode();
cPar = pCur->GetByte();
if ( eOp == ocPush )
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index fc08062c965f..2e4977ced2ee 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -657,9 +657,10 @@ const ScRefList* ScRefListToken::GetRefList() const { return &aRefList;
bool ScRefListToken::IsArrayResult() const { return mbArrayResult; }
bool ScRefListToken::operator==( const FormulaToken& r ) const
{
- const ScRefListToken* p;
- return FormulaToken::operator==( r ) && &aRefList == r.GetRefList() &&
- ((p = dynamic_cast<const ScRefListToken*>(&r)) != nullptr) && mbArrayResult == p->IsArrayResult();
+ if (!FormulaToken::operator==( r ) || &aRefList != r.GetRefList())
+ return false;
+ const ScRefListToken* p = dynamic_cast<const ScRefListToken*>(&r);
+ return p && mbArrayResult == p->IsArrayResult();
}
ScMatrixToken::ScMatrixToken( const ScMatrixRef& p ) :
@@ -2168,22 +2169,26 @@ void ScTokenArray::MergeRangeReference( const ScAddress & rPos )
if (!pCode || !nLen)
return;
sal_uInt16 nIdx = nLen;
- FormulaToken *p1, *p2, *p3; // ref, ocRange, ref
+
// The actual types are checked in extendRangeReference().
- if (((p3 = PeekPrev(nIdx)) != nullptr) &&
- (((p2 = PeekPrev(nIdx)) != nullptr) && p2->GetOpCode() == ocRange) &&
- ((p1 = PeekPrev(nIdx)) != nullptr))
+ FormulaToken *p3 = PeekPrev(nIdx); // ref
+ if (!p3)
+ return;
+ FormulaToken *p2 = PeekPrev(nIdx); // ocRange
+ if (!p2 || p2->GetOpCode() != ocRange)
+ return;
+ FormulaToken *p1 = PeekPrev(nIdx); // ref
+ if (!p1)
+ return;
+ FormulaTokenRef p = extendRangeReference( *mxSheetLimits, *p1, *p3, rPos, true);
+ if (p)
{
- FormulaTokenRef p = extendRangeReference( *mxSheetLimits, *p1, *p3, rPos, true);
- if (p)
- {
- p->IncRef();
- p1->DecRef();
- p2->DecRef();
- p3->DecRef();
- nLen -= 2;
- pCode[ nLen-1 ] = p.get();
- }
+ p->IncRef();
+ p1->DecRef();
+ p2->DecRef();
+ p3->DecRef();
+ nLen -= 2;
+ pCode[ nLen-1 ] = p.get();
}
}
@@ -2267,28 +2272,28 @@ bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend,
switch ( eDir )
{
case DIR_BOTTOM :
- if ( rPos.Row() < mxSheetLimits->mnMaxRow )
- nRow = (nExtend = rPos.Row()) + 1;
- else
+ if ( rPos.Row() >= mxSheetLimits->mnMaxRow )
return false;
+ nExtend = rPos.Row();
+ nRow = nExtend + 1;
break;
case DIR_RIGHT :
- if ( rPos.Col() < mxSheetLimits->mnMaxCol )
- nCol = static_cast<SCCOL>(nExtend = rPos.Col()) + 1;
- else
+ if ( rPos.Col() >= mxSheetLimits->mnMaxCol )
return false;
+ nExtend = rPos.Col();
+ nCol = static_cast<SCCOL>(nExtend) + 1;
break;
case DIR_TOP :
- if ( rPos.Row() > 0 )
- nRow = (nExtend = rPos.Row()) - 1;
- else
+ if ( rPos.Row() <= 0 )
return false;
+ nExtend = rPos.Row();
+ nRow = nExtend - 1;
break;
case DIR_LEFT :
- if ( rPos.Col() > 0 )
- nCol = static_cast<SCCOL>(nExtend = rPos.Col()) - 1;
- else
+ if ( rPos.Col() <= 0 )
return false;
+ nExtend = rPos.Col();
+ nCol = static_cast<SCCOL>(nExtend) - 1;
break;
default:
OSL_FAIL( "unknown Direction" );