folly: avoid used-uninitialized bug in a test
authorJim Meyering <meyering@fb.com>
Thu, 11 Sep 2014 22:23:17 +0000 (15:23 -0700)
committerDave Watson <davejwatson@fb.com>
Mon, 15 Sep 2014 21:30:11 +0000 (14:30 -0700)
Summary:
Clang complained about this.
* folly/gen/test/FileBenchmark.cpp (BENCHMARK): Initialize "rfd" to -1
and verify that it is set to something nonnegative in the first
BENCHMARK_SUSPEND block.

Test Plan:
Run this:
fbconfig -r --clang --with-project-version clang:dev folly/gen && fbmake runtests
and observe that compilation now succeeds. (and test results remain unchanged)

Reviewed By: tudorb@fb.com

Subscribers: njormrod

FB internal diff: D1551180

Tasks: 4090011

folly/gen/test/FileBenchmark.cpp

index 61e7220e0ab2f27def9129b3d02318a5c648d5b5..21ae8677d936548355fe40d4fcf6b28167d45cb0 100644 (file)
@@ -25,7 +25,7 @@ using namespace folly::gen;
 
 BENCHMARK(ByLine_Pipes, iters) {
   std::thread thread;
-  int rfd;
+  int rfd = -1;
   int wfd;
   BENCHMARK_SUSPEND {
     int p[2];
@@ -46,6 +46,7 @@ BENCHMARK(ByLine_Pipes, iters) {
     PCHECK(::read(rfd, &buf, 1) == 1);  // wait for startup
   }
 
+  CHECK_ERR(rfd >= 0);
   auto s = byLine(folly::File(rfd)) | eachTo<int64_t>() | sum;
   folly::doNotOptimizeAway(s);