Bug 20725 – Taking address of potentially null struct member isn't safe

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-08T03:22:36Z
Last change time
2020-04-08T05:30:50Z
Keywords
safe
Assigned to
No Owner
Creator
Mathias LANG
See also
https://issues.dlang.org/show_bug.cgi?id=20722

Comments

Comment #0 by pro.mathias.lang — 2020-04-08T03:22:36Z
``` import std.stdio; struct Bar { ubyte[0x7FFF_FFE] memory1 = void; ubyte[0x7FFF_FFE] memory2 = void; ubyte[0x7FFF_FFE] memory3 = void; int oops = void; } void main () @safe { Bar* b; int* ptr = &b.oops; assert(ptr !is null); writeln(ptr); } ``` Ouputs: ``` 17FFFFFC ``` And is very obviously violating @safety promises. Originally reported by Rainers in https://issues.dlang.org/show_bug.cgi?id=20722.
Comment #1 by r.sagitario — 2020-04-08T05:30:50Z
Discussed in https://issues.dlang.org/show_bug.cgi?id=5176 *** This issue has been marked as a duplicate of issue 5176 ***