Fix out-of-bounds std::vector access.

In the `Ranges(...)` generation code a "control" vector which stores
the current index for each range passed to `Ranges`. Previously this vector
was incorrectly initialized to the size of the subranges not the number
of subranges.

Additionally this patch suppresses unused warnings generated by
`stream_init_anchor`.
This commit is contained in:
Eric Fiselier 2016-08-28 23:07:38 -06:00
parent cbcd7b656e
commit db1af86d16
3 changed files with 8 additions and 2 deletions

View File

@ -216,7 +216,7 @@ Benchmark* RegisterBenchmarkInternal(Benchmark*);
// Ensure that the standard streams are properly initialized in every TU.
int InitializeStreams();
static int stream_init_anchor = InitializeStreams();
BENCHMARK_UNUSED static int stream_init_anchor = InitializeStreams();
} // end namespace internal

View File

@ -553,7 +553,7 @@ void BenchmarkImp::Ranges(const std::vector<std::pair<int, int>>& ranges) {
total *= arglists[i].size();
}
std::vector<std::size_t> ctr(total, 0);
std::vector<std::size_t> ctr(arglists.size(), 0);
for (int i = 0; i < total; i++) {
std::vector<int> tmp;

View File

@ -43,4 +43,10 @@ BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
BENCHMARK_REGISTER_F(MultipleRangesFixture, Empty)->RangeMultiplier(2)->Ranges({{1, 2}, {3, 7}, {5, 15}})->Args({7, 6, 3});
static void BM_MultipleRanges(benchmark::State& st) {
while (st.KeepRunning()) {}
}
BENCHMARK(BM_MultipleRanges)->Ranges({{5, 5}, {6, 6}});
BENCHMARK_MAIN()