[llvm] r342461 - [Xray] llvm-xray fix possible segfault

David Carlier via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 18 03:31:10 PDT 2018


Author: devnexen
Date: Tue Sep 18 03:31:10 2018
New Revision: 342461

URL: http://llvm.org/viewvc/llvm-project?rev=342461&view=rev
Log:
[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

Modified:
    llvm/trunk/tools/llvm-xray/xray-account.cpp

Modified: llvm/trunk/tools/llvm-xray/xray-account.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-account.cpp?rev=342461&r1=342460&r2=342461&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-account.cpp (original)
+++ llvm/trunk/tools/llvm-xray/xray-account.cpp Tue Sep 18 03:31:10 2018
@@ -358,8 +358,11 @@ void LatencyAccountant::exportStats(cons
     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));




More information about the llvm-commits mailing list