From e829478c6a3a55d8e5c1227e2678dcc18d518609 Mon Sep 17 00:00:00 2001 From: leveldb Team Date: Tue, 21 Jan 2025 16:19:03 +0000 Subject: [PATCH] Fix speculatively some "placement new" issues in leveldb cl/713346733 changed the type of some variables to pointers, but didn't adjust the placement new statements. From pkasting@: "I suspect your code is wrong and will crash. An array is a pointer, so taking its address also gives a pointer, which is why it compiles; but the value of that pointer is different. You're no longer providing the address of the storage, but rather the address of the array pointer." PiperOrigin-RevId: 717926210 --- util/env_posix.cc | 2 +- util/env_windows.cc | 2 +- util/no_destructor.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index 57c19ec70..c2490322e 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -880,7 +880,7 @@ class SingletonEnv { "env_storage_ does not meet the Env's alignment needs"); static_assert(alignof(SingletonEnv) % alignof(EnvType) == 0, "env_storage_ does not meet the Env's alignment needs"); - new (&env_storage_) EnvType(); + new (env_storage_) EnvType(); } ~SingletonEnv() = default; diff --git a/util/env_windows.cc b/util/env_windows.cc index e0a19cc5e..ae5149a50 100644 --- a/util/env_windows.cc +++ b/util/env_windows.cc @@ -775,7 +775,7 @@ class SingletonEnv { "env_storage_ does not meet the Env's alignment needs"); static_assert(alignof(SingletonEnv) % alignof(EnvType) == 0, "env_storage_ does not meet the Env's alignment needs"); - new (&env_storage_) EnvType(); + new (env_storage_) EnvType(); } ~SingletonEnv() = default; diff --git a/util/no_destructor.h b/util/no_destructor.h index 08ce6a40a..c28a10731 100644 --- a/util/no_destructor.h +++ b/util/no_destructor.h @@ -28,7 +28,7 @@ class NoDestructor { static_assert( alignof(NoDestructor) % alignof(InstanceType) == 0, "instance_storage_ does not meet the instance's alignment requirement"); - new (&instance_storage_) + new (instance_storage_) InstanceType(std::forward(constructor_args)...); }