From: Dmitry Panin Date: Thu, 6 Nov 2014 20:47:43 +0000 (-0800) Subject: Fix integer overflow in folly/Benchmark.cpp X-Git-Tag: v0.22.0~191 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=53c9c964ce4ce3b7b2965dc75b840a9a3f1d2d1c;p=folly.git Fix integer overflow in folly/Benchmark.cpp 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 --- diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index 940fe91c..66bcf7c1 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -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));