Bug 123025 - ReDim Preserve fails if array is filled by Split
Summary: ReDim Preserve fails if array is filled by Split
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.1.0
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2019-01-28 22:49 UTC by Gerhard Weydt
Modified: 2021-03-27 18:36 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Weydt 2019-01-28 22:49:04 UTC
If an array is filled by the Split function, subsequent use of ReDim always emties the array, regardless whether it worked befor.

Try this test code (Xray has been used because it easily displays the array; if you don't want to install it, use msgbox arr(0) instead, seeing arr(0) empty will be convincing enough). The Xray calls are numbered to fit the output below.

sub test

dim s as string, arr(1) as string

arr(0) = "aa"
arr(1) = "bb"
Xray arr  '[1]
ReDim Preserve arr(1)
Xray arr  '[2]

s = "a/b"
arr = Split(s, "/")
Xray arr  '[3]
ReDim Preserve arr(1)
Xray arr  '[4]

arr(0) = "aa"
arr(1) = "bb"
Xray arr  '[5]
ReDim Preserve arr(1)
Xray arr  '[6]

end sub

Executing this macro you will get:

[1] after entering data: correct
          Tabelle : T( 0 To 1 ) As string  
 
(0)       | string : "aa"
(1)       | string : "bb"

[2] after ReDim Preserve: correct
          Tabelle : T( 0 To 1 ) As string  
 
(0)       | string : "aa"
(1)       | string : "bb"

[3] after assigning the values by Split: correct
          Tabelle : T( 0 To 1 ) As variant  
 
(0)       | string : "a"
(1)       | string : "b"

[4] after ReDim Preserve: w r o n g
          Tabelle : T( 0 To 1 ) As empty  
 
(0)       | <empty> 
(1)       | <empty> 

[5] after entering new data: still wrong, even though this should be as in [1]
          Tabelle : T( 0 To 1 ) As empty  
 
(0)       | <empty> 
(1)       | <empty> 

[6] after ReDim Preserve: wrong, consequently
          Tabelle : T( 0 To 1 ) As empty  
 
(0)       | <empty> 
(1)       | <empty> 

So it seems that assigning values to the array by Split does something wrong to the array, such that ReDim Preserve cannot find the correct information.
Comment 1 Oliver Brinzing 2019-01-29 18:03:06 UTC
already reproducible with AOO 4.1.5

it will work if the variable "arr" is a variant, e.g.

dim arr() as variant
or
dim arr()
Comment 2 himajin100000 2019-02-08 05:31:49 UTC
https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=48314f25#1638
https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=48314f25#1644

Changing these SbxVARIANT to SbxSTRING seems to do the trick, but I'm not sure I'm doing things correctly.
Comment 3 himajin100000 2019-02-08 05:48:39 UTC
Investigating...

==================
REM  *****  BASIC  *****
Option Explicit
sub test

dim s as string 
dim arr(1) as Integer

s = "a/b"
arr = Split(s, "/")
Msgbox(arr(0))
ReDim Preserve arr(1)
Msgbox(arr(0))

end sub

Showing "a" in Msgbox Functions(though arr is declared as an array of Integer)
Comment 4 himajin100000 2019-02-08 11:00:46 UTC
Hmmm...It seems the new problem I pointed out was not related to Split function

Option Explicit 
Sub Main
	Dim a(1) As Integer
	Dim b(1) As String
	b = a
End Sub

runs without error.
Comment 5 Commit Notification 2020-10-06 15:18:51 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/698e5d54182d96a1fd0c3b864ba0e618f82dd1f1

tdf#123025 - fixed broken tests for cverr method

It will be available in 7.1.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.
Comment 6 Commit Notification 2020-10-16 10:31:53 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d6b7cc3f7c07b98c90194e8b33cf44b94804b525

tdf#123025 - ReDim Preserve fails if array is filled by Split

It will be available in 7.1.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.
Comment 7 Andreas Heinisch 2020-10-16 12:16:44 UTC
Credits go to  himajin100000@gmail.com for pointing out the problem as well.