Bug 136755 - Unexpected result when executing Redim statement on an array of structures
Summary: Unexpected result when executing Redim statement on an array of structures
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
Whiteboard: target:7.2.0
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
Reported: 2020-09-14 15:55 UTC by Vladimir Sokolinskiy
Modified: 2021-01-25 06:59 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Sokolinskiy 2020-09-14 15:55:59 UTC
Run Basic Macro:

Sub RunRedim
    Dim aPropertyValues(0) As New com.sun.star.beans.PropertyValue
    ReDim aPropertyValues(5) As com.sun.star.beans.PropertyValue
    Msgbox Ubound(aPropertyValues)
End Sub

Result of Msgbox: 0

Expected: 5

Version: (x64)
Build ID: 7cbcfc562f6eb6708b5ff7d7397325de9e764452
CPU threads: 6; OS: Windows 10.0 Build 18363; UI render: default; VCL: win
Locale: ru-RU (ru_RU); ИП: ru-RU
Calc: threaded
Comment 1 Oliver Brinzing 2020-09-15 14:48:32 UTC
already reproducible with:

LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-
Comment 2 Andreas Heinisch 2020-11-28 19:54:08 UTC
Some observations:

In https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#3870 the information about the array dimension is lost and then it cannot be redimensioned in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#2151. After I re-added the parameters, the array will get the new dimensions, and the new objects for the redimensioned array will be created in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#4440. 

However, the old array somehow survives in the expression stack and will be read for the UBound function, leading to the error.
Comment 3 Andreas Heinisch 2020-12-23 09:29:31 UTC
Some additional findings:

The script does indeed work with ReDim Preserve, where the only additional command  generated by the compiler is StepREDIMP_ERASE and DCREATE_REDIMP_ instead of DCREATE_. Atm, SbiRuntime::StepDCREATE and SbiRuntime::StepDCREATE_REDIMP are the same.

At runtime, the function SbiRuntime::StepREDIMP_ERASE copies a reference to the array and reuses it in SbiRuntime::CheckArray, where it prevents the retrieval of a new array element using the old reference.

Without Preserve, the first element of the array will be passed as an argument, leading to missing dimensions in SbiRuntime::DimImpl. However, I don't know how to retrieve the correct variable SbiRuntime::CheckArray without breaking additional functionalities.
Comment 4 Commit Notification 2021-01-25 06:58:29 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":


tdf#136755, tdf#124008 - delete the variable beforehand REDIM

It will be available in 7.2.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:

Affected users are encouraged to test the fix and report feedback.