Issue 20725 - Taking address of potentially null struct member isn't safe
Summary: Taking address of potentially null struct member isn't safe
Status: RESOLVED DUPLICATE of issue 5176
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: safe
Depends on:
Blocks:
 
Reported: 2020-04-08 03:22 UTC by Mathias LANG
Modified: 2020-04-08 05:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2020-04-08 03:22:36 UTC
```
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 Rainer Schuetze 2020-04-08 05:30:50 UTC
Discussed in https://issues.dlang.org/show_bug.cgi?id=5176

*** This issue has been marked as a duplicate of issue 5176 ***