diff options
author | Tom Stellard <tstellar@redhat.com> | 2018-10-22 16:37:14 +0000 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2018-10-22 16:37:14 +0000 |
commit | eb0722e28e734de2b7ce39c52d4ce7e53f222550 (patch) | |
tree | c5d5815fe327cd4e8690b50b6fe7863ad8ceba67 | |
parent | 888225e7beebbdd82f6b6c7e139c2b094ea4faaa (diff) |
Merging r342461:
------------------------------------------------------------------------
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
-rw-r--r-- | tools/llvm-xray/xray-account.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/llvm-xray/xray-account.cpp b/tools/llvm-xray/xray-account.cpp index 2776a888848..77de1de496f 100644 --- a/tools/llvm-xray/xray-account.cpp +++ b/tools/llvm-xray/xray-account.cpp @@ -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)); |