[Lldb-commits] [lldb] 873b79b - Don't access reference to a vector after pop_back

Benjamin Kramer via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 7 14:11:04 PDT 2020


Author: Benjamin Kramer
Date: 2020-04-07T23:10:58+02:00
New Revision: 873b79b8675d0c8eca6055ae8a874fe52b033c28

URL: https://github.com/llvm/llvm-project/commit/873b79b8675d0c8eca6055ae8a874fe52b033c28
DIFF: https://github.com/llvm/llvm-project/commit/873b79b8675d0c8eca6055ae8a874fe52b033c28.diff

LOG: Don't access reference to a vector after pop_back

This is undefined behavior. Found by asan's detect_container_overflow.

Added: 
    

Modified: 
    lldb/source/Target/ThreadPlanStack.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/ThreadPlanStack.cpp b/lldb/source/Target/ThreadPlanStack.cpp
index 44e47f385a82..c51946aae71c 100644
--- a/lldb/source/Target/ThreadPlanStack.cpp
+++ b/lldb/source/Target/ThreadPlanStack.cpp
@@ -156,7 +156,7 @@ void ThreadPlanStack::PushPlan(lldb::ThreadPlanSP new_plan_sp) {
 lldb::ThreadPlanSP ThreadPlanStack::PopPlan() {
   assert(m_plans.size() > 1 && "Can't pop the base thread plan");
 
-  lldb::ThreadPlanSP &plan_sp = m_plans.back();
+  lldb::ThreadPlanSP plan_sp = std::move(m_plans.back());
   m_completed_plans.push_back(plan_sp);
   plan_sp->WillPop();
   m_plans.pop_back();
@@ -166,7 +166,7 @@ lldb::ThreadPlanSP ThreadPlanStack::PopPlan() {
 lldb::ThreadPlanSP ThreadPlanStack::DiscardPlan() {
   assert(m_plans.size() > 1 && "Can't discard the base thread plan");
 
-  lldb::ThreadPlanSP &plan_sp = m_plans.back();
+  lldb::ThreadPlanSP plan_sp = std::move(m_plans.back());
   m_discarded_plans.push_back(plan_sp);
   plan_sp->WillPop();
   m_plans.pop_back();


        


More information about the lldb-commits mailing list