Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly initialise memory when REDIMming with UDT #497

Merged

Conversation

flukiluke
Copy link
Contributor

This closes #331 with the addition of calls to ZeroMemory() as needed to zero out numeric variables in UDTs with variable length strings.

While implementing that I also found issues with redimming arrays of regular numeric UDTs; the address to start zeroing was off by one. To make this logic a little cleaner we no longer keep track of whether a UDT element should be aligned to a whole number of bytes - they already effectively were, since _BIT types are not allowed in a UDT (this code seemed to be trying to allow for a hypothetical sub-byte alignment).

At some point we may want to revisit this to enforce certain alignments of fields, but that should not be a concern of allocarray() and will never be packing multiple values into one byte.

flukiluke added 3 commits June 1, 2024 20:07
This allows simplifying how the size of UDT arrays are calculated,
and thus not leave memory uninitialised when doing a redim that
expands the array size.
allocarray() previously assumed a variable size UDT had only
variable-length strings. This caused any numeric elements to
remain uninitialised.
@flukiluke flukiluke merged commit 91eab72 into QB64-Phoenix-Edition:main Jun 2, 2024
4 checks passed
@flukiluke flukiluke deleted the redim_preserve_reinit branch June 2, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

If a Type contains a variable-length String, then the other members don't get zero'd during a ReDim _Preserve
5 participants