diff options
author | Eike Rathke <erack@redhat.com> | 2016-03-22 17:16:07 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-24 10:26:17 +0000 |
commit | a5867a0d676981c27b36a4def9b423fabf6862e8 (patch) | |
tree | 0927e3d48df8d09620114ad41f990aeafa48389b /sc | |
parent | e3d06146f648faf35b475d536f3a9c6fd55ea188 (diff) |
Resolves: tdf#98642 comparing RPN insufficient in shared formula detection
(cherry picked from commit d6b32653ad34f0879ad1ada421a3a2655dd766e1)
Backported.
Change-Id: I78812c2d6fdb3464ccc2ebeee901a76f675effa4
Reviewed-on: https://gerrit.libreoffice.org/23436
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index d9f48e1f38ee..eb24423f10d7 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3885,7 +3885,7 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r break; case formula::svIndex: { - if(pThisTok->GetIndex() != pOtherTok->GetIndex()) + if(pThisTok->GetIndex() != pOtherTok->GetIndex() || pThisTok->IsGlobal() != pOtherTok->IsGlobal()) return NotEqual; } break; @@ -3909,6 +3909,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->IsGlobal() != pOtherTok->IsGlobal()) + return NotEqual; + } + break; + default: + ; + } + } + return bInvariant ? EqualInvariant : EqualRelativeRef; } |