summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-03-22 17:16:07 +0100
committerEike Rathke <erack@redhat.com>2016-03-22 17:22:43 +0100
commitd6b32653ad34f0879ad1ada421a3a2655dd766e1 (patch)
tree5a8bdf3b93f2f19344d034d98ec2c408ed2a68e6
parent9e05463f4b482a89c36159c57a80dd61474b9b9c (diff)
Resolves: tdf#98642 comparing RPN insufficient in shared formula detection
Change-Id: I78812c2d6fdb3464ccc2ebeee901a76f675effa4
-rw-r--r--sc/source/core/data/formulacell.cxx47
1 files changed, 46 insertions, 1 deletions
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index f91dc213a1f2..4f602d642b07 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -3914,7 +3914,7 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r
break;
case formula::svIndex:
{
- if(pThisTok->GetIndex() != pOtherTok->GetIndex())
+ if(pThisTok->GetIndex() != pOtherTok->GetIndex() || pThisTok->GetSheet() != pOtherTok->GetSheet())
return NotEqual;
}
break;
@@ -3938,6 +3938,51 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r
}
}
+ // If still the same, check lexical names as different names may result in
+ // identical RPN code.
+
+ pThis = pCode->GetArray();
+ nThisLen = pCode->GetLen();
+ pOther = rOther.pCode->GetArray();
+ nOtherLen = rOther.pCode->GetLen();
+
+ if ( !pThis || !pOther )
+ {
+ // Error: no code for cells !"
+ return NotEqual;
+ }
+
+ if ( nThisLen != nOtherLen )
+ return NotEqual;
+
+ for ( sal_uInt16 i = 0; i < nThisLen; i++ )
+ {
+ formula::FormulaToken *pThisTok = pThis[i];
+ formula::FormulaToken *pOtherTok = pOther[i];
+
+ if ( pThisTok->GetType() != pOtherTok->GetType() ||
+ pThisTok->GetOpCode() != pOtherTok->GetOpCode() ||
+ pThisTok->GetParamCount() != pOtherTok->GetParamCount() )
+ {
+ // Incompatible type, op-code or param counts.
+ return NotEqual;
+ }
+
+ switch (pThisTok->GetType())
+ {
+ // All index tokens are names. Different categories already had
+ // different OpCode values.
+ case formula::svIndex:
+ {
+ if (pThisTok->GetIndex() != pOtherTok->GetIndex() || pThisTok->GetSheet() != pOtherTok->GetSheet())
+ return NotEqual;
+ }
+ break;
+ default:
+ ;
+ }
+ }
+
return bInvariant ? EqualInvariant : EqualRelativeRef;
}