Bug 22709 – [dip1000] slice of static array can be escaped in @safe using ref arguments

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-27T21:55:22Z
Last change time
2022-01-28T11:51:35Z
Keywords
pull
Assigned to
No Owner
Creator
Ate Eskola

Comments

Comment #0 by Ajieskola — 2022-01-27T21:55:22Z
This compiles both with and without -dip1000: ------ @safe: void escape(ref ubyte[] arr, ref ubyte[64] local) { arr = local; } ubyte[] getArr() { ubyte[64] blob; ubyte[] arr; escape(arr, blob); return arr; // Use this at your peril. } ------ I believe the compiler should figure out with -dip1000 that: 1: Non-return ref "local" in "escape" is being assigned to another ref variable, so an error should result. 2: Even if "escape" was correctly annotated, "arr" in "getArr" is scope and thus cannot be returned.
Comment #1 by dlang-bot — 2022-01-28T09:33:39Z
@dkorpel created dlang/dmd pull request #13577 "Fix issue 22709 - [dip1000] slice of static array can be escaped in @safe using ref arguments" fixing this issue: - Fix issue 22709 - [dip1000] slice of static array can be escaped in @safe using ref arguments https://github.com/dlang/dmd/pull/13577
Comment #2 by dlang-bot — 2022-01-28T11:51:35Z
dlang/dmd pull request #13577 "Fix issue 22709 - [dip1000] slice of static array can be escaped in @safe using ref arguments" was merged into master: - 092dc2ddbb3bb78903ba32a74c01c9278b252c7e by dkorpel: Fix issue 22709 - [dip1000] slice of static array can be escaped in @safe using ref arguments https://github.com/dlang/dmd/pull/13577