Bug 20793 – Variant equals of different types

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-02T13:00:10Z
Last change time
2024-12-01T16:36:39Z
Assigned to
No Owner
Creator
MrSmith33
Moved to GitHub: phobos#9792 →

Comments

Comment #0 by mrsmith33 — 2020-05-02T13:00:10Z
Code to reproduce: --- struct S1 { ubyte a; ubyte[64] u; } struct S2 { ubyte a; ubyte[64] u; } void main(){ import std.variant, std.stdio; Variant var1 = Variant(S1(1)); Variant var2 = Variant(const S1(2)); writefln("%s", var1 == var2); } --- Problem is in these lines https://github.com/dlang/phobos/blob/22055634e4b455135cebb65a2d562f21472c1e88/std/variant.d#L416-L418 Address to temp.store is passed to tryPutting, which expects address to memory of A.sizeof. So, tryPutting writes A.sizeof bytes into &temp.store corrupting the stack.
Comment #1 by robert.schadek — 2024-12-01T16:36:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9792 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB