Commit e4866b94 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[base] Fix undefined behaviour in LazyInstanceImpl.

Patch from Thomas Köppe <tkoeppe@google.com>.

Change-Id: I7ae2e001b6bd72ad67baad64d35e7c17d4ed4716
Reviewed-on: https://chromium-review.googlesource.com/806221Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49838}
parent 03b4d391
...@@ -168,17 +168,13 @@ struct LazyInstanceImpl { ...@@ -168,17 +168,13 @@ struct LazyInstanceImpl {
typedef typename AllocationTrait::StorageType StorageType; typedef typename AllocationTrait::StorageType StorageType;
private: private:
static void InitInstance(StorageType* storage) { static void InitInstance(void* storage) {
AllocationTrait::template InitStorageUsingTrait<CreateTrait>(storage); AllocationTrait::template InitStorageUsingTrait<CreateTrait>(
static_cast<StorageType*>(storage));
} }
void Init() const { void Init() const {
InitOnceTrait::Init( InitOnceTrait::Init(&once_, &InitInstance, static_cast<void*>(&storage_));
&once_,
// Casts to void* are needed here to avoid breaking strict aliasing
// rules.
reinterpret_cast<void(*)(void*)>(&InitInstance), // NOLINT
reinterpret_cast<void*>(&storage_));
} }
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment