You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible data corruption when assigning variant to itself #164
@SergeyIvanov87 - It looks like you're correct but I vaguely recall having some reasons for not having a check. I'll need to dig through history to see why implementation ended up like this and if we need to fix it. Thanks!
This struck me as well. i'm upgrading it from "possible" to "definite".
I fixed it by adding if(&rhs==this) return; to copy_assign() and move_assign() but I don't really have a lot of confidence that's technically correct. Nevertheless it did fix my manifestation of the problem and I didn't immediately see any other bad consequences.
@SergeyIvanov87@mgambrell@springmeyer - I don't remember why there's no check for the self assignment. I can only think that at some point operaror= signature was :
VARIANT_INLINE variant<Types...>& operator=(variant<Types...> other) // <--- pass by value
I'll take a look at adding the test tomorrow, thanks!
Activity
springmeyer commentedon Jan 11, 2018
/cc @artemp
artemp commentedon Jan 12, 2018
@SergeyIvanov87 - It looks like you're correct but I vaguely recall having some reasons for not having a check. I'll need to dig through history to see why implementation ended up like this and if we need to fix it. Thanks!
mgambrell commentedon Aug 11, 2019
This struck me as well. i'm upgrading it from "possible" to "definite".
I fixed it by adding
if(&rhs==this) return;to copy_assign() and move_assign() but I don't really have a lot of confidence that's technically correct. Nevertheless it did fix my manifestation of the problem and I didn't immediately see any other bad consequences.artemp commentedon Aug 12, 2019
@SergeyIvanov87 @mgambrell @springmeyer - I don't remember why there's no check for the self assignment. I can only think that at some point operaror= signature was :
I'll take a look at adding the test tomorrow, thanks!
add self-assignment checks in copy and move assignment operator= (ref #…