Description: Macro optional parameter is incorrectly initialized to the default integer value with Option VBASupport 1 Steps to Reproduce: Run Macro Test. Option Explicit Option VbaSupport 1 Sub Mysub(Optional ByVal arg1 As Variant=1) Msgbox arg1 End Sub Sub Test Mysub End Sub Actual Results: Shows 1% Expected Results: MUST show 1 Reproducible: Always User Profile Reset: No Additional Info:
Repro: Version: 7.2.0.2 (x64) / LibreOffice Community Build ID: 614be4f5c67816389257027dc5e56c801a547089 CPU threads: 12; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win Locale: ru-RU (ru_RU); UI: en-US Calc: threaded
Looks like "%" is the type character, read at SbiRuntime::StepPARAM using 'pImg->GetString( nDefaultId )'. It is assigned to a variable of type Variant, which happily accepts string as is, without conversion to integer.
The special characters will be added in SbiStringPool::Add. For instance, Option Explicit Option VbaSupport 1 Sub Mysub(Optional ByVal arg1 As Variant=100000) Msgbox arg1 End Sub Sub Test Mysub End Sub produces 100000&
(In reply to Andreas Heinisch from comment #3) Thinking about it, I see how the type character is unsafe in case of the default arguments. Yet, the type is really needed... Looking at SbiImage::GetString, I see that a string in the pool can't have a 0 character inside (the strings are 0-terminated). Yet, we can write such a character in the middle; and we can learn the size of the string by taking offset of the next string, so we may know that there are more characters there. Can we use embedded 0 to separate number string from its type char maybe?
(In reply to Mike Kaganski from comment #4) What about something like: short SbiStringPool::Add( double n, SbxDataType t, bool bAddSuffixType ) and snprintf(buf, sizeof(buf), "%d%s", static_cast<short>(n), bAddSuffixType ? "%" : "");
Andreas Heinisch committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/3bcfb1aac1f43f16c579486264103ebd4f3f829b tdf#143707 - Change strategy to support suffix type characters It will be available in 7.3.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.