Skip to content

Commit

Permalink
UB: reinterpret_cast pointer without using launder
Browse files Browse the repository at this point in the history
Signed-off-by: wineway <[email protected]>
  • Loading branch information
wineway committed Dec 6, 2023
1 parent 068d5ee commit 5db9232
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
#include "util/env_posix_test_helper.h"
#include "util/posix_logger.h"

#ifdef __cpp_lib_launder
#define LAUNDER(x) std::launder((x))
#else
#define LAUNDER(x) x
#endif

namespace leveldb {

namespace {
Expand Down Expand Up @@ -883,7 +889,7 @@ class SingletonEnv {
SingletonEnv(const SingletonEnv&) = delete;
SingletonEnv& operator=(const SingletonEnv&) = delete;

Env* env() { return reinterpret_cast<Env*>(&env_storage_); }
Env* env() { return LAUNDER(reinterpret_cast<Env*>(&env_storage_)); }

static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
Expand Down

0 comments on commit 5db9232

Please sign in to comment.