Bug 22219 – core.lifetime emplace is unsafe with void[] override
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-08-16T20:28:46Z
Last change time
2021-08-23T09:17:36Z
Keywords
pull
Assigned to
No Owner
Creator
João Lourenço
Comments
Comment #0 by jlourenco5691 — 2021-08-16T20:28:46Z
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
}
---
Comment #1 by dlang-bot — 2021-08-16T20:44:21Z
@iK4tsu updated dlang/druntime pull request #3545 "Fix Issue 22219 - core.lifetime emplace is unsafe with void[] override" fixing this issue:
- core.lifetime: fix class only function emplace system cast from a void[]
The emplace function is already making all the needed safety checks for casting.
The cast only happens if both the length and alignment are compliant with the
type requested, allowing it to be safe.
Fix Issue 22219 - core.lifetime emplace is unsafe with void[] override
Signed-off-by: João Lourenço <[email protected]>
- core.lifetime: fix non class function emplace system casts from a void[]
The emplace function is already making all the needed safety checks for casting.
The cast only happens if both the length and alignment are compliant with the
type requested, allowing it to be safe.
Fix Issue 22219 - core.lifetime emplace is unsafe with void[] override
Signed-off-by: João Lourenço <[email protected]>
https://github.com/dlang/druntime/pull/3545