From df1d4bd528027c60bcab2f2e0a87303610fad326 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 4 Aug 2018 20:10:55 +0200 Subject: ScCompiler::IsString, pass down the string length if we know it instead of making the constructor first perform strlen (normally for the second time). And drop an unnecessary if (.. > MAXSTRLEN) which is impossible to hit, since we check that before adding to this array. Change-Id: I8ef2e027fb4a22e06be81e8b5955350869599d85 Reviewed-on: https://gerrit.libreoffice.org/58597 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/core/tool/compiler.cxx | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 831f8ec677f1..446f1b08f86f 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -2703,7 +2703,7 @@ Label_MaskStateMachine: --nSrcPos; } if ( bAutoCorrect ) - aCorrectedSymbol = cSymbol; + aCorrectedSymbol = OUString(cSymbol, pSym - cSymbol); if (bAutoIntersection && nSpaces > 1) --nSpaces; // replace '!!' with only one space return nSpaces; @@ -2996,25 +2996,17 @@ bool ScCompiler::IsValue( const OUString& rSym ) bool ScCompiler::IsString() { - const sal_Unicode* p = cSymbol; + if ( cSymbol[0] != '"' ) + return false; + const sal_Unicode* p = cSymbol+1; while ( *p ) p++; sal_Int32 nLen = sal::static_int_cast( p - cSymbol - 1 ); - bool bQuote = ((cSymbol[0] == '"') && (cSymbol[nLen] == '"')); - if ((bQuote ? nLen-2 : nLen) > MAXSTRLEN) - { - SetError(FormulaError::StringOverflow); + if (cSymbol[nLen] != '"') return false; - } - if ( bQuote ) - { - cSymbol[nLen] = '\0'; - const sal_Unicode* pStr = cSymbol+1; - svl::SharedString aSS = pDoc->GetSharedStringPool().intern(OUString(pStr)); - maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase()); - return true; - } - return false; + svl::SharedString aSS = pDoc->GetSharedStringPool().intern(OUString(cSymbol+1, nLen-1)); + maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase()); + return true; } bool ScCompiler::IsPredetectedErrRefReference( const OUString& rName, const OUString* pErrRef ) -- cgit