[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

llvm-svn: 342461
This commit is contained in:
David Carlier 2018-09-18 10:31:10 +00:00
parent 821a116818
commit 38a20c2a52
1 changed files with 5 additions and 2 deletions

View File

@ -358,8 +358,11 @@ void LatencyAccountant::exportStats(const XRayFileHeader &Header, F Fn) const {
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));