Skip to content

Copying array by ref from dictionary #15

@mias1wot

Description

@mias1wot

When I allocate an array and copy it to another array by ref - everything works just fine. But if I add an array to a dictionary and try to copy it by reference, the result array will have incorrect boundaries and trying to do any action with the new variable will make the Excel crash.

Sub Works()
    Dim a() As Variant
    ReDim a(2, 2)
    a(0, 0) = 1
    
    Dim b As Variant
    b = GetArrayByRef(a)
    
    b(1, 1) = 4
End Sub

Sub ExcelCrashes()
    Dim a() As Variant
    ReDim a(2, 2)
    a(0, 0) = 1
    
    Dim dict As New Dictionary
    dict.Add 0, a
    
    
    Dim b As Variant
    b = GetArrayByRef(dict(0)) ' The memory is not allocated properly here.
    
    b(1, 1) = 4 ' Excel crash.
End Sub

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions