diff options
author | leveldb Team <no-reply@google.com> | 2025-01-21 16:19:03 +0000 |
---|---|---|
committer | Victor Costan <costan@google.com> | 2025-01-24 21:05:34 +0000 |
commit | e829478c6a3a55d8e5c1227e2678dcc18d518609 (patch) | |
tree | b10a934fbd029360d7d7f96f54f01663b6993b95 | |
parent | 302786e211d1f2e6fd260261f642d03a91e5922c (diff) | |
download | leveldb-e829478c6a3a55d8e5c1227e2678dcc18d518609.tar.gz leveldb-e829478c6a3a55d8e5c1227e2678dcc18d518609.zip |
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
-rw-r--r-- | util/env_posix.cc | 2 | ||||
-rw-r--r-- | util/env_windows.cc | 2 | ||||
-rw-r--r-- | 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 57c19ec..c249032 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<EnvType>) % 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 e0a19cc..ae5149a 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<EnvType>) % 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 08ce6a4..c28a107 100644 --- a/util/no_destructor.h +++ b/util/no_destructor.h @@ -28,7 +28,7 @@ class NoDestructor { static_assert( alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0, "instance_storage_ does not meet the instance's alignment requirement"); - new (&instance_storage_) + new (instance_storage_) InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...); } |