Skip to content

Possible data corruption when assigning variant to itself #164

@SergeyIvanov87

Description

@SergeyIvanov87

Hi, Thanks to you variant implementation!
But i see, that there are issue in member

VARIANT_INLINE variant<Types...>& operator=(variant<Types...> 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<Types...> 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions