Skip to content

Commit e829478

Browse files
leveldb Teampwnall
leveldb Team
authored andcommitted
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
1 parent 302786e commit e829478

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

util/env_posix.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ class SingletonEnv {
880880
"env_storage_ does not meet the Env's alignment needs");
881881
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
882882
"env_storage_ does not meet the Env's alignment needs");
883-
new (&env_storage_) EnvType();
883+
new (env_storage_) EnvType();
884884
}
885885
~SingletonEnv() = default;
886886

util/env_windows.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class SingletonEnv {
775775
"env_storage_ does not meet the Env's alignment needs");
776776
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
777777
"env_storage_ does not meet the Env's alignment needs");
778-
new (&env_storage_) EnvType();
778+
new (env_storage_) EnvType();
779779
}
780780
~SingletonEnv() = default;
781781

util/no_destructor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class NoDestructor {
2828
static_assert(
2929
alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0,
3030
"instance_storage_ does not meet the instance's alignment requirement");
31-
new (&instance_storage_)
31+
new (instance_storage_)
3232
InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...);
3333
}
3434

0 commit comments

Comments
 (0)