diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-11-27 03:55:05 +0300 |
---|---|---|
committer | Eric <eric@efcs.ca> | 2018-11-26 19:55:05 -0500 |
commit | c9f2693ea97e94c8afcefb57d3074c6a6236ca23 (patch) | |
tree | dbb2282b66057ef9de899397d40307505473ad82 | |
parent | c9311a44e1280853632fe2472345dd04514a2f74 (diff) | |
download | google-benchmark-c9f2693ea97e94c8afcefb57d3074c6a6236ca23.tar.gz |
StrFormat() is a printf-like function, mark it as such, fix fallout. (#727)
Fixes #714.
-rw-r--r-- | src/benchmark_register.cc | 11 | ||||
-rw-r--r-- | src/string_util.h | 6 | ||||
-rw-r--r-- | test/reporter_output_test.cc | 12 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/benchmark_register.cc b/src/benchmark_register.cc index a85a4b4..f17f5b2 100644 --- a/src/benchmark_register.cc +++ b/src/benchmark_register.cc @@ -182,14 +182,19 @@ bool BenchmarkFamilies::FindBenchmarks( } } - instance.name += StrFormat("%d", arg); + // we know that the args are always non-negative (see 'AddRange()'), + // thus print as 'unsigned'. BUT, do a cast due to the 32-bit builds. + instance.name += StrFormat("%lu", static_cast<unsigned long>(arg)); ++arg_i; } if (!IsZero(family->min_time_)) instance.name += StrFormat("/min_time:%0.3f", family->min_time_); - if (family->iterations_ != 0) - instance.name += StrFormat("/iterations:%d", family->iterations_); + if (family->iterations_ != 0) { + instance.name += + StrFormat("/iterations:%lu", + static_cast<unsigned long>(family->iterations_)); + } if (family->repetitions_ != 0) instance.name += StrFormat("/repeats:%d", family->repetitions_); diff --git a/src/string_util.h b/src/string_util.h index 4a55012..fc5f8b0 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -12,7 +12,11 @@ void AppendHumanReadable(int n, std::string* str); std::string HumanReadableNumber(double n, double one_k = 1024.0); -std::string StrFormat(const char* format, ...); +#ifdef __GNUC__ +__attribute__((format(printf, 1, 2))) +#endif +std::string +StrFormat(const char* format, ...); inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { return out; diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc index 8a45471..35bb9b2 100644 --- a/test/reporter_output_test.cc +++ b/test/reporter_output_test.cc @@ -220,6 +220,18 @@ ADD_CASES(TC_JSONOut, ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/5/third:4\",%csv_report$"}}); // ========================================================================= // +// ------------------------ Testing Big Args Output ------------------------ // +// ========================================================================= // + +void BM_BigArgs(benchmark::State& state) { + for (auto _ : state) { + } +} +BENCHMARK(BM_BigArgs)->RangeMultiplier(2)->Range(1U << 30U, 1U << 31U); +ADD_CASES(TC_ConsoleOut, {{"^BM_BigArgs/1073741824 %console_report$"}, + {"^BM_BigArgs/2147483648 %console_report$"}}); + +// ========================================================================= // // ----------------------- Testing Complexity Output ----------------------- // // ========================================================================= // |