Skip to content

Commit

Permalink
Fix speculatively some "placement new" issues in leveldb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leveldb Team authored and pwnall committed Jan 24, 2025
1 parent 302786e commit e829478
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion util/env_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion util/no_destructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)...);
}

Expand Down

0 comments on commit e829478

Please sign in to comment.