[Issue 20725] New: Taking address of potentially null struct member isn't safe
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Apr  8 03:22:36 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=20725
          Issue ID: 20725
           Summary: Taking address of potentially null struct member isn't
                    safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com
```
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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list