Bug 22781 – assert escapes reference to expired stack frame

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-16T18:50:12Z
Last change time
2022-02-17T06:37:01Z
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-02-16T18:50:12Z
As of DMD 2.098.1, the following program compiles, runs, and exhibits undefined behavior: --- void main() @safe { char[4] message = "oops"; assert(0, message[]); } --- Example output: --- [email protected](4): P�;� ---------------- ??:? _d_assert_msg [0x55583733f7b0] ??:? _Dmain [0x55583733f724] --- Instead of "oops", a corrupted message is printed.
Comment #1 by Ajieskola — 2022-02-16T19:27:23Z
Fortunately prevented by -preview=dip1000 though. Is the plan to fix these static array issues in all D or just with -preview=dip1000? It's going to break an awful lot of code if we forbid slicing static arrays in vanilla D, but otherwise it's never going to be safe.
Comment #2 by bugzilla — 2022-02-17T06:37:01Z
Since dip1000 catches it, it's not a bug. dip1000 will eventually be the default.