You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the below code, if you have a Type that contains a variable-length String entry along with other members and you use ReDim _Preserve to resize an array of those types, the new variable-length String's are initialize but the other members are not and contain garbage:
Type foo
a As Long
s As String
End Type
ReDim bar(20) As foo
bar(20).a = 20
bar(20).s = "foobar"
' This should effectively clear out the last 10 array entries
ReDim _Preserve bar(10) As foo
ReDim _Preserve bar(20) As foo
Print "bar(20).a: "; bar(20).a ' Incorrectly prints 20, it was not cleared
Print "bar(20).s: "; bar(20).s ' Correctly prints nothing, an empty string
The underlying issue is that around lines 13796 in qb64pe.bas there is separate logic for rediming an array depending on whether the type contains variable-length Strings or not. The version for Type's with variable-length strings correctly free's and initializes the strings contained in the Type, but it does not call ZeroMemory() to zero the rest of the new memory for the array. The redim logic for typical types does this zeroing, so that works correctly.
A separate point, the freeing and creation of the qbs entries seems to be quite slow. It would be nice if we could simply leave them as NULL pointers and then treat them as the empty string when they're used. That would avoid needing custom initialization logic for them and also make them more efficient by only creating the qbss if they actually get assigned.
The text was updated successfully, but these errors were encountered:
See the below code, if you have a
Type
that contains a variable-length String entry along with other members and you useReDim _Preserve
to resize an array of those types, the new variable-length String's are initialize but the other members are not and contain garbage:The underlying issue is that around lines 13796 in
qb64pe.bas
there is separate logic for rediming an array depending on whether the type contains variable-length Strings or not. The version for Type's with variable-length strings correctly free's and initializes the strings contained in theType
, but it does not callZeroMemory()
to zero the rest of the new memory for the array. The redim logic for typical types does this zeroing, so that works correctly.A separate point, the freeing and creation of the
qbs
entries seems to be quite slow. It would be nice if we could simply leave them asNULL
pointers and then treat them as the empty string when they're used. That would avoid needing custom initialization logic for them and also make them more efficient by only creating theqbs
s if they actually get assigned.The text was updated successfully, but these errors were encountered: