From e4866b94e1feebe347c01233912bca22fed77e1c Mon Sep 17 00:00:00 2001 From: Ulan Degenbaev Date: Mon, 4 Dec 2017 16:52:55 +0100 Subject: [PATCH] [base] Fix undefined behaviour in LazyInstanceImpl. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from Thomas Köppe . Change-Id: I7ae2e001b6bd72ad67baad64d35e7c17d4ed4716 Reviewed-on: https://chromium-review.googlesource.com/806221 Reviewed-by: Michael Lippautz Commit-Queue: Ulan Degenbaev Cr-Commit-Position: refs/heads/master@{#49838} --- src/base/lazy-instance.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/base/lazy-instance.h b/src/base/lazy-instance.h index 92f9b309a7..e965382b8d 100644 --- a/src/base/lazy-instance.h +++ b/src/base/lazy-instance.h @@ -168,17 +168,13 @@ struct LazyInstanceImpl { typedef typename AllocationTrait::StorageType StorageType; private: - static void InitInstance(StorageType* storage) { - AllocationTrait::template InitStorageUsingTrait(storage); + static void InitInstance(void* storage) { + AllocationTrait::template InitStorageUsingTrait( + static_cast(storage)); } void Init() const { - InitOnceTrait::Init( - &once_, - // Casts to void* are needed here to avoid breaking strict aliasing - // rules. - reinterpret_cast(&InitInstance), // NOLINT - reinterpret_cast(&storage_)); + InitOnceTrait::Init(&once_, &InitInstance, static_cast(&storage_)); } public: