Possible data corruption when assigning variant to itself
@artemp is already working on this.
Since Jan 11, 2018.
- Dominant language
- C++
- Stars
- 384
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
Hi, Thanks to you variant implementation!
But i see, that there are issue in member
```
VARIANT_INLINE variant& operator=(variant const& other)
{
copy_assign(other);
return *this;
}
```
Now there are no check for `&other ==this` and `copy_assign` can destroy variant member data's before actual copy to itself
```
VARIANT_INLINE void copy_assign(variant const& rhs)
{
helper_type::destroy(type_index, &data);
type_index = detail::invalid_value;
helper_type::copy(rhs.type_index, &rhs.data, &data);
type_index = rhs.type_index;
}
```
So, in result `helper_type::copy(rhs.type_index, &rhs.data, &data);` can operate with invalid data
Best Regards
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.