diff options
author | Dennis Francis <dennis.francis@collabora.co.uk> | 2017-11-17 14:05:56 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.co.uk> | 2017-11-21 16:09:44 +0530 |
commit | 4284cdcc3e82bf2a6029ce2502c82605d9a74f86 (patch) | |
tree | b028c88b98e78a00ef002429385eaadba48275cf /sc | |
parent | 1f9d91afac6e32507a99ea3507ab40c1b9cb9a0e (diff) |
Type check the tokens before reuse
If the exisiting token is of wrong type, create and use a fresh new
token instead.
Change-Id: I348b0972306497dfe7eae0655c9b93d5830cb740
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/formulagroup.cxx | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index f5b90416e95f..a29030557032 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -206,13 +206,26 @@ public: if ( !pTargetTok ) aCode2.AddString(rPool.intern(OUString(pStr))); else - pTargetTok->SetString(rPool.intern(OUString(pStr))); + { + if ( pTargetTok->GetType() == formula::svString ) + pTargetTok->SetString(rPool.intern(OUString(pStr))); + else + { + formula::FormulaStringToken* pStrTok = new formula::FormulaStringToken(rPool.intern(OUString(pStr))); + aCode2.ReplaceToken(nTokIdx, pStrTok, formula::FormulaTokenArray::CODE_ONLY); + } + } } else if (rtl::math::isNan(fVal)) { // Value of NaN represents an empty cell. if ( !pTargetTok ) aCode2.AddToken(ScEmptyCellToken(false, false)); + else if ( pTargetTok->GetType() != formula::svEmptyCell ) + { + ScEmptyCellToken* pEmptyTok = new ScEmptyCellToken(false, false); + aCode2.ReplaceToken(nTokIdx, pEmptyTok, formula::FormulaTokenArray::CODE_ONLY); + } } else { @@ -220,7 +233,15 @@ public: if ( !pTargetTok ) aCode2.AddDouble(fVal); else - pTargetTok->GetDoubleAsReference() = fVal; + { + if ( pTargetTok->GetType() == formula::svDouble ) + pTargetTok->GetDoubleAsReference() = fVal; + else + { + formula::FormulaDoubleToken* pDoubleTok = new formula::FormulaDoubleToken( fVal ); + aCode2.ReplaceToken(nTokIdx, pDoubleTok, formula::FormulaTokenArray::CODE_ONLY); + } + } } } break; |