From: Hannes Roth Date: Wed, 24 Jun 2015 15:55:44 +0000 (-0700) Subject: (Wangle) Possibly undefined behavior in collect X-Git-Tag: v0.48.0~20 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fa33147273be70b6c796fc83c086897ac06d6a40;p=folly.git (Wangle) Possibly undefined behavior in collect Summary: Not sure if this is really undefined behavior or whether UBSAN is just super paranoid. Will try to read up on it later. I also changed some other `std::atomic` initialization to always follow the same pattern, let me know if I should revert those. I couldn't resist, OCD kicked in. idonthaveocd Reviewed By: @fugalh Differential Revision: D2181074 --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 22816e91..7fdc09da 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -600,7 +600,7 @@ struct CollectContext { } Promise p; InternalResult result; - std::atomic threw; + std::atomic threw {false}; }; // Specialize for void (implementations in Future.cpp) @@ -660,9 +660,9 @@ collectAny(InputIterator first, InputIterator last) { typename std::iterator_traits::value_type::value_type T; struct CollectAnyContext { - CollectAnyContext(size_t n) : done(false) {}; + CollectAnyContext(size_t n) {}; Promise>> p; - std::atomic done; + std::atomic done {false}; }; auto ctx = std::make_shared(std::distance(first, last)); @@ -752,10 +752,10 @@ std::vector> window(Collection input, F func, size_t n) { struct WindowContext { WindowContext(Collection&& i, F&& fn) - : i_(0), input_(std::move(i)), promises_(input_.size()), + : input_(std::move(i)), promises_(input_.size()), func_(std::move(fn)) {} - std::atomic i_; + std::atomic i_ {0}; Collection input_; std::vector> promises_; F func_; @@ -872,10 +872,10 @@ template Future Future::within(Duration dur, E e, Timekeeper* tk) { struct Context { - Context(E ex) : exception(std::move(ex)), promise(), token(false) {} + Context(E ex) : exception(std::move(ex)), promise() {} E exception; Promise promise; - std::atomic token; + std::atomic token {false}; }; auto ctx = std::make_shared(std::move(e)); diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 02651591..c0e09d09 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -414,7 +414,7 @@ struct CollectVariadicContext { } Promise> p; std::tuple results; - std::atomic threw; + std::atomic threw {false}; typedef Future> type; };