asio icon indicating copy to clipboard operation
asio copied to clipboard

UB in impl/awaitable.hpp

Open linuxnyasha opened this issue 11 months ago • 0 comments

template <typename T, typename Executor>
class awaitable_frame

contains

alignas(T) unsigned char result_[sizeof(T)]; 
  T get()
  {
    this->caller_ = nullptr;
    this->rethrow_exception();
    return std::move(*static_cast<T*>(static_cast<void*>(result_)));
  }
  ~awaitable_frame()
{
  if (has_result_)
    static_cast<T*>(static_cast<void*>(result_))->~T();
}

But a simple static cast is used into a void* and to the T*, but the pointer from this does not point to the object, see [basic.life], so you need to std::launder it before using.

linuxnyasha avatar Mar 20 '24 09:03 linuxnyasha