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 | dfebe573431425a385738e5644ea417d67f87689 (patch) | |
tree | 17734d8550af21cce63a2367401e8dde6843a4c8 | |
parent | 0447cd66a07d649515953ce36caacd849a1d390c (diff) | |
download | llvm-dfebe573431425a385738e5644ea417d67f87689.zip llvm-dfebe573431425a385738e5644ea417d67f87689.tar.gz llvm-dfebe573431425a385738e5644ea417d67f87689.tar.bz2 |
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
------------------------------------------------------------------------
llvm-svn: 344918
-rw-r--r-- | llvm/tools/llvm-xray/xray-account.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/tools/llvm-xray/xray-account.cpp b/llvm/tools/llvm-xray/xray-account.cpp index 2776a88..77de1de 100644 --- a/llvm/tools/llvm-xray/xray-account.cpp +++ b/llvm/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)); |