(Wangle) Possibly undefined behavior in collect
authorHannes Roth <hannesr@fb.com>
Wed, 24 Jun 2015 15:55:44 +0000 (08:55 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 24 Jun 2015 16:41:05 +0000 (09:41 -0700)
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

folly/futures/Future-inl.h
folly/futures/detail/Core.h

index 22816e91dd6fc537f5cf3762b941ec1627f326f3..7fdc09dae8dbaee41c66f8d18c24df1f146e09e2 100644 (file)
@@ -600,7 +600,7 @@ struct CollectContext {
   }
   Promise<Result> p;
   InternalResult result;
-  std::atomic<bool> threw;
+  std::atomic<bool> threw {false};
 };
 
 // Specialize for void (implementations in Future.cpp)
@@ -660,9 +660,9 @@ collectAny(InputIterator first, InputIterator last) {
     typename std::iterator_traits<InputIterator>::value_type::value_type T;
 
   struct CollectAnyContext {
-    CollectAnyContext(size_t n) : done(false) {};
+    CollectAnyContext(size_t n) {};
     Promise<std::pair<size_t, Try<T>>> p;
-    std::atomic<bool> done;
+    std::atomic<bool> done {false};
   };
 
   auto ctx = std::make_shared<CollectAnyContext>(std::distance(first, last));
@@ -752,10 +752,10 @@ std::vector<Future<Result>>
 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<size_t> i_;
+    std::atomic<size_t> i_ {0};
     Collection input_;
     std::vector<Promise<Result>> promises_;
     F func_;
@@ -872,10 +872,10 @@ template <class E>
 Future<T> Future<T>::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<T> promise;
-    std::atomic<bool> token;
+    std::atomic<bool> token {false};
   };
   auto ctx = std::make_shared<Context>(std::move(e));
 
index 0265159120a5b4b30a085c24e699a4c9458ccf02..c0e09d099e7a6dfef80dbf9745f6ab2ec5bf416b 100644 (file)
@@ -414,7 +414,7 @@ struct CollectVariadicContext {
   }
   Promise<std::tuple<Ts...>> p;
   std::tuple<Ts...> results;
-  std::atomic<bool> threw;
+  std::atomic<bool> threw {false};
   typedef Future<std::tuple<Ts...>> type;
 };