mirror of
https://gitee.com/openharmony/third_party_benchmark
synced 2024-11-23 15:30:48 +00:00
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:
parent
cbcd7b656e
commit
db1af86d16
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user