[Issue 22219] New: core.lifetime emplace is unsafe with void[] override
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 16 20:28:46 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22219
Issue ID: 22219
Summary: core.lifetime emplace is unsafe with void[] override
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: jlourenco5691 at gmail.com
The emplace function is safety checking for both the length and alignment
before casting to the requested type, allowing the cast to be safe.
---
import core.lifetime;
void main() @safe
{
ubyte[int.sizeof] buf = void;
auto i = emplace!int(buf, 4); // fails
}
---
workaround:
---
import core.lifetime;
void main() @safe
{
ubyte[int.sizeof] tmp = void;
auto buf = (() @trusted => cast(int*)(tmp.ptr))();
auto i = emplace(buf, 4); // uses the T* variant
}
---
--
More information about the Digitalmars-d-bugs
mailing list