summaryrefslogtreecommitdiff
path: root/basic/source/comp/symtbl.cxx
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-08-03 20:56:22 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2021-08-10 12:23:19 +0200
commit3bcfb1aac1f43f16c579486264103ebd4f3f829b (patch)
tree359a6d297ee164857ecc61055f3866b791bbe770 /basic/source/comp/symtbl.cxx
parentd5c8684c05e33e87033d595c98fb50acd42d56a8 (diff)
tdf#143707 - Change strategy to support suffix type characters
In order to support the correct data type of numeric constants, booleans, and default values for strings, the strategy to transport the data type character to the runtime has been changed. The type character will be added after the literal and the string termination symbol in order to keep compatibility. This allows to retrieve the correct type in StepLOADNC and in StepPARAM. Any legacy written images are still possible to process, since if there is a suffix type character where the data type character was directly written after the numeric constant, it will be processed in StepLOADNC. Without this fix, an optional parameter of type Variant, would still include the suffixe type character, and will not be converted to the correct type in StepPARAM. Change-Id: I86c8192c6dc28457053fa7b23a073420e45407b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119945 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Diffstat (limited to 'basic/source/comp/symtbl.cxx')
-rw-r--r--basic/source/comp/symtbl.cxx43
1 files changed, 34 insertions, 9 deletions
diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx
index ed245a364874..6fb7f081d853 100644
--- a/basic/source/comp/symtbl.cxx
+++ b/basic/source/comp/symtbl.cxx
@@ -61,24 +61,49 @@ short SbiStringPool::Add( const OUString& rVal )
return static_cast<short>(++n);
}
-short SbiStringPool::Add( double n, SbxDataType t )
+short SbiStringPool::Add(double n, SbxDataType t)
{
- char buf[40]{};
+ size_t size = 0;
+ const size_t aBufLength = 40;
+ char buf[aBufLength]{};
+
+ // tdf#143707 - add the type character after the null termination of the string in order to
+ // keep compatibility. After the type character has been added, the buffer contains the value
+ // of the double n, the string termination symbol, and the type character.
switch( t )
{
// tdf#142460 - properly handle boolean values in string pool
- case SbxBOOL: snprintf( buf, sizeof(buf), "%db", static_cast<short>(n) ); break;
+ case SbxBOOL:
+ size = snprintf(buf, sizeof(buf), "%d", static_cast<short>(n)) + 1;
+ buf[size++] = 'b';
+ break;
// tdf#131296 - store numeric value including its type character
// See GetSuffixType in basic/source/comp/scanner.cxx for type characters
- case SbxINTEGER: snprintf( buf, sizeof(buf), "%d%%", static_cast<short>(n) ); break;
+ case SbxINTEGER:
+ size = snprintf(buf, sizeof(buf), "%d", static_cast<short>(n)) + 1;
+ buf[size++] = '%';
+ break;
case SbxLONG:
- snprintf( buf, sizeof(buf), "%" SAL_PRIdINT32 "&", static_cast<sal_Int32>(n) ); break;
- case SbxSINGLE: snprintf( buf, sizeof(buf), "%.6g!", static_cast<float>(n) ); break;
- case SbxDOUBLE: snprintf( buf, sizeof(buf), "%.16g", n ); break; // default processing in SbiRuntime::StepLOADNC - no type character
- case SbxCURRENCY: snprintf(buf, sizeof(buf), "%.16g@", n); break;
+ size = snprintf(buf, sizeof(buf), "%" SAL_PRIdINT32, static_cast<sal_Int32>(n)) + 1;
+ buf[size++] = '&';
+ break;
+ case SbxSINGLE:
+ size = snprintf(buf, sizeof(buf), "%.6g", static_cast<float>(n)) + 1;
+ buf[size++] = '!';
+ break;
+ case SbxDOUBLE:
+ size = snprintf(buf, sizeof(buf), "%.16g", n) + 1;
+ buf[size++] = '#';
+ break;
+ case SbxCURRENCY:
+ size = snprintf(buf, sizeof(buf), "%.16g", n) + 1;
+ buf[size++] = '@';
+ break;
default: assert(false); break; // should not happen
}
- return Add( OUString::createFromAscii( buf ) );
+
+ // tdf#143707 - add the content of the buffer to the string pool inclding its calculated length
+ return Add(OUString::createFromAscii(std::string_view(buf, size)));
}
SbiSymPool::SbiSymPool( SbiStringPool& r, SbiSymScope s, SbiParser* pP ) :