Skip to content

Commit 183e79a

Browse files
leveldb Teamfanquake
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 82c3104 commit 183e79a

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
@@ -860,7 +860,7 @@ class SingletonEnv {
860860
"env_storage_ does not meet the Env's alignment needs");
861861
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
862862
"env_storage_ does not meet the Env's alignment needs");
863-
new (&env_storage_) EnvType();
863+
new (env_storage_) EnvType();
864864
}
865865
~SingletonEnv() = default;
866866

util/env_windows.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ class SingletonEnv {
808808
"env_storage_ does not meet the Env's alignment needs");
809809
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
810810
"env_storage_ does not meet the Env's alignment needs");
811-
new (&env_storage_) EnvType();
811+
new (env_storage_) EnvType();
812812
}
813813
~SingletonEnv() = default;
814814

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)