------------------------------------------------------------------------
r342461 | devnexen | 2018-09-18 03:31:10 -0700 (Tue, 18 Sep 2018) | 10 lines
[Xray] llvm-xray fix possible segfault
top argument when superior to the instrumentated code list capacity can lead to a segfault.
Reviewers: dberris
Reviewed By: dberris
Differential Revision: https://reviews.llvm.org/D52224
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@344918
91177308-0d34-0410-b5e6-
96231b3b80d8
break;
}
- if (AccountTop > 0)
- Results.erase(Results.begin() + AccountTop.getValue(), Results.end());
+ if (AccountTop > 0) {
+ auto MaxTop =
+ std::min(AccountTop.getValue(), static_cast<int>(Results.size()));
+ Results.erase(Results.begin() + MaxTop, Results.end());
+ }
for (const auto &R : Results)
Fn(std::get<0>(R), std::get<1>(R), std::get<2>(R));