From 39080c90768c509796fb34d8239814b4a814e445 Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Tue, 11 Aug 2015 16:11:11 -0700 Subject: [PATCH] (Wangle) Align lambdaBuf_ Summary: Not aligning `lambdaBuf_` can lead to unaligned reads, which can be a problem on some platforms. We use `lambdaBuf_` to store a type of up to `lambdaBufSize`, so aligning it to that should always be safe. Reviewed By: @alexshap Differential Revision: D2319347 --- folly/futures/detail/Core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index efbf2616..252af04a 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -148,7 +148,7 @@ class Core { // Move the lambda into the Core if it fits if (sizeof(LambdaBufHelper) <= lambdaBufSize) { - auto funcLoc = static_cast*>((void*)lambdaBuf_); + auto funcLoc = reinterpret_cast*>(&lambdaBuf_); new (funcLoc) LambdaBufHelper(std::forward(func)); callback_ = std::ref(*funcLoc); } else { @@ -366,7 +366,7 @@ class Core { // lambdaBuf occupies exactly one cache line static constexpr size_t lambdaBufSize = 8 * sizeof(void*); - char lambdaBuf_[lambdaBufSize]; + typename std::aligned_storage::type lambdaBuf_; // place result_ next to increase the likelihood that the value will be // contained entirely in one cache line folly::Optional> result_; -- 2.34.1