Fix UB in heap init example docs #376
Open
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
_heap_sizeis not actually a valid address anywhere (of course we have to treat it as an address since it is a linker symbol), and therefore creating a reference to it, even as an intermediate step, is undefined behavior. It seems in debug mode rust will panic if we create a reference to null (e.g. if_heap_sizeis zero) even though we aren't attempting to access it.This is just quick fix to replace that line with
addr_of!which doesn't create an intermediate reference and therefore no longer UB. The macro is apparently now soft deprecated and suggests replacement with&raw constdirectly, but kept the macro for consistency with its other uses in code base.