Make sure that SbiImage::GetString sets peType

And flatten the function.

Change-Id: I3d8c3e7a7fcc8879be0c6f38094ef2716500a367
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191567
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski
2025-09-27 17:57:13 +02:00
parent 771a93e3be
commit 674918bcaf
2 changed files with 40 additions and 40 deletions
+39 -39
View File
@@ -619,53 +619,53 @@ void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
}
// Note: IDs start with 1
OUString SbiImage::GetString( sal_uInt32 nId, SbxDataType *eType ) const
OUString SbiImage::GetString(sal_uInt32 nId, SbxDataType* peType) const
{
if( nId && nId <= mvStringOffsets.size() )
if (nId < 1 || nId > mvStringOffsets.size())
{
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
sal_Unicode* pStr = pStrings.get() + nOff;
if (peType)
*peType = SbxEMPTY;
return {};
}
sal_uInt32 nNextOff = (nId < mvStringOffsets.size()) ? mvStringOffsets[ nId ] : nStringSize;
sal_uInt32 nLen = nNextOff - nOff - 1;
// #i42467: Special treatment for vbNullChar
if (*pStr == 0)
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
sal_Unicode* pStr = pStrings.get() + nOff;
sal_uInt32 nNextOff = (nId < mvStringOffsets.size()) ? mvStringOffsets[ nId ] : nStringSize;
sal_uInt32 nLen = nNextOff - nOff - 1;
OUString aOUStr(pStr);
// #i42467: Special treatment for vbNullChar
if (aOUStr.isEmpty() && nLen == 1)
{
if (peType)
*peType = SbxSTRING;
return OUString(u'\0');
}
// tdf#143707 - check if the data type character was added after the string termination
// symbol. It was added in basic/source/comp/symtbl.cxx.
if (peType)
{
*peType = SbxSTRING;
if (o3tl::make_unsigned(aOUStr.getLength()) < nLen)
{
if( nLen == 1 )
const sal_Unicode pTypeChar = *(pStr + aOUStr.getLength() + 1);
switch (pTypeChar)
{
return OUString( u'\0');
// See GetSuffixType in basic/source/comp/scanner.cxx for type characters
case '%': *peType = SbxINTEGER; break;
case '&': *peType = SbxLONG; break;
case '!': *peType = SbxSINGLE; break;
case '#': *peType = SbxDOUBLE; break;
case '@': *peType = SbxCURRENCY; break;
// tdf#142460 - properly handle boolean values in string pool
case 'b': *peType = SbxBOOL; break; // Not in GetSuffixType
// tdf#168569 - support date values in string pool
case 'd': *peType = SbxDATE; break; // Not in GetSuffixType
}
}
else
{
// tdf#143707 - check if the data type character was added after the string termination
// symbol. It was added in basic/source/comp/symtbl.cxx.
OUString aOUStr(pStr);
if (eType != nullptr)
{
*eType = SbxSTRING;
if (o3tl::make_unsigned(aOUStr.getLength()) < nLen)
{
const sal_Unicode pTypeChar = *(pStrings.get() + nOff + aOUStr.getLength() + 1);
switch (pTypeChar)
{
// See GetSuffixType in basic/source/comp/scanner.cxx for type characters
case '%': *eType = SbxINTEGER; break;
case '&': *eType = SbxLONG; break;
case '!': *eType = SbxSINGLE; break;
case '#': *eType = SbxDOUBLE; break;
case '@': *eType = SbxCURRENCY; break;
// tdf#142460 - properly handle boolean values in string pool
case 'b': *eType = SbxBOOL; break;
// tdf#168569 - support date values in string pool
case 'd': *eType = SbxDATE; break; // Not in GetSuffixType
}
}
}
return aOUStr;
}
}
return OUString();
return aOUStr;
}
const SbxObject* SbiImage::FindType (const OUString& aTypeName) const
+1 -1
View File
@@ -84,7 +84,7 @@ public:
const sal_uInt8* GetCode() const { return aCode.data(); }
sal_uInt32 GetCodeSize() const { return aCode.size(); }
sal_uInt16 GetBase() const { return nDimBase; }
OUString GetString( sal_uInt32 nId, SbxDataType *eType = nullptr ) const;
OUString GetString(sal_uInt32 nId, SbxDataType* peType = nullptr) const;
const SbxObject* FindType (const OUString& aTypeName) const;
const SbxArrayRef& GetEnums() const { return rEnums; }