Fix integer overflow in folly/Benchmark.cpp
authorDmitry Panin <panin@fb.com>
Thu, 6 Nov 2014 20:47:43 +0000 (12:47 -0800)
committerPavlo Kushnir <pavlo@fb.com>
Sat, 8 Nov 2014 02:40:13 +0000 (18:40 -0800)
Summary:
`bm_max_secs` has type int32
So when this value is more than 2, expression
```
FLAGS_bm_max_secs * 1000000000;
```
overflows

Test Plan:
I did put a
```
LOG(INFO) << timeBudgetInNs;
```
and observed correct values (before fix they were overflowed)

Reviewed By: antonl@fb.com

Subscribers: njormrod, folly-diffs@

FB internal diff: D1663247

Signature: t1:1663247:1415261814:c9154ffde183b2a4f5403e534e47e52e8276c61b

folly/Benchmark.cpp

index 940fe91c27e81bdba1fd883fff220ef9b4c77b27..66bcf7c1e76c4b0a9f7bb1277d9febddc2ad897e 100644 (file)
@@ -222,7 +222,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun,
   static const unsigned int epochs = 1000;
   // We establish a total time budget as we don't want a measurement
   // to take too long. This will curtail the number of actual epochs.
-  const uint64_t timeBudgetInNs = FLAGS_bm_max_secs * 1000000000;
+  const uint64_t timeBudgetInNs = FLAGS_bm_max_secs * 1000000000ULL;
   timespec global;
   CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &global));