mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-02 14:04:36 +02:00
Fix undefined behaviour with default casting implementations. Null pointers can't be dereferenced, so return a value constructed smart pointer in those cases.
This commit is contained in:
@@ -223,7 +223,7 @@ struct pointer_traits
|
|||||||
|
|
||||||
template<class UPtr>
|
template<class UPtr>
|
||||||
static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
||||||
{ return pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))); }
|
{ return uptr ? pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))) : pointer(); }
|
||||||
|
|
||||||
//priv_const_cast_from
|
//priv_const_cast_from
|
||||||
template<class UPtr>
|
template<class UPtr>
|
||||||
@@ -232,7 +232,7 @@ struct pointer_traits
|
|||||||
|
|
||||||
template<class UPtr>
|
template<class UPtr>
|
||||||
static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
||||||
{ return pointer_to(const_cast<element_type&>(*uptr)); }
|
{ return uptr ? pointer_to(const_cast<element_type&>(*uptr)) : pointer(); }
|
||||||
|
|
||||||
//priv_dynamic_cast_from
|
//priv_dynamic_cast_from
|
||||||
template<class UPtr>
|
template<class UPtr>
|
||||||
@@ -241,15 +241,7 @@ struct pointer_traits
|
|||||||
|
|
||||||
template<class UPtr>
|
template<class UPtr>
|
||||||
static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr)
|
||||||
{
|
{ return uptr ? pointer_to(dynamic_cast<element_type&>(*uptr)) : pointer(); }
|
||||||
element_type *p = dynamic_cast<element_type*>(&*uptr);
|
|
||||||
if(!p){
|
|
||||||
return pointer();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return pointer_to(*p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
///@endcond
|
///@endcond
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user