Commit db1af86d by Eric Fiselier

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`.
parent cbcd7b65
...@@ -216,7 +216,7 @@ Benchmark* RegisterBenchmarkInternal(Benchmark*); ...@@ -216,7 +216,7 @@ Benchmark* RegisterBenchmarkInternal(Benchmark*);
// Ensure that the standard streams are properly initialized in every TU. // Ensure that the standard streams are properly initialized in every TU.
int InitializeStreams(); int InitializeStreams();
static int stream_init_anchor = InitializeStreams(); BENCHMARK_UNUSED static int stream_init_anchor = InitializeStreams();
} // end namespace internal } // end namespace internal
......
...@@ -553,7 +553,7 @@ void BenchmarkImp::Ranges(const std::vector<std::pair<int, int>>& ranges) { ...@@ -553,7 +553,7 @@ void BenchmarkImp::Ranges(const std::vector<std::pair<int, int>>& ranges) {
total *= arglists[i].size(); 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++) { for (int i = 0; i < total; i++) {
std::vector<int> tmp; std::vector<int> tmp;
......
...@@ -43,4 +43,10 @@ BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) { ...@@ -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}); 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() BENCHMARK_MAIN()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment