fix UBSAN failure in atomic_shared_ptr_test
authorIlya Maykov <ilyam@fb.com>
Fri, 23 Jun 2017 22:43:48 +0000 (15:43 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 23 Jun 2017 22:51:16 +0000 (15:51 -0700)
Summary: Fix UBSAN failure in atomic_shared_ptr_test by using reinterpret_cast instead of static_cast.

Reviewed By: yfeldblum

Differential Revision: D5314116

fbshipit-source-id: 8479c9c4bdeeb155067a3de75efe4e97c36519e5

folly/experimental/detail/AtomicSharedPtr-detail.h

index bd416cb..02d8be0 100644 (file)
@@ -68,8 +68,8 @@ class shared_ptr_internals {
       return (T*)inplace;
     }
     // Could also be a _Sp_counted_deleter, but the layout is the same
-    auto ptr =
-        static_cast<std::_Sp_counted_ptr<const void*, std::_S_atomic>*>(base);
+    using derived_type = std::_Sp_counted_ptr<const void*, std::_S_atomic>;
+    auto ptr = reinterpret_cast<derived_type*>(base);
     return (T*)(ptr->*fieldPtr(access_counted_ptr_ptr{}));
   }