From 5767ca4dc73689f79e4bae73d28d5943eccf797d Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 3 Apr 2017 01:02:54 -0400 Subject: [PATCH] Fix bug in formula debugger The debugger used a deque, but added elements to it while iterating over it. Since it didn't rely on the random access property, I simply replaced it with list. Also, there was an incorrect use of erase(). --- src/formula/debugger.cpp | 18 +++++++++--------- src/formula/debugger.hpp | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/formula/debugger.cpp b/src/formula/debugger.cpp index 147d31c1dcd3..293046b821db 100644 --- a/src/formula/debugger.cpp +++ b/src/formula/debugger.cpp @@ -120,7 +120,7 @@ void formula_debugger::add_debug_info(int arg_number, const std::string& f_name) } -const std::deque& formula_debugger::get_call_stack() const +const std::list& formula_debugger::get_call_stack() const { return call_stack_; } @@ -131,20 +131,20 @@ const breakpoint_ptr formula_debugger::get_current_breakpoint() const return current_breakpoint_; } -const std::deque& formula_debugger::get_execution_trace() const +const std::list& formula_debugger::get_execution_trace() const { return execution_trace_; } void formula_debugger::check_breakpoints() { - for( std::deque< breakpoint_ptr >::iterator b = breakpoints_.begin(); b!= breakpoints_.end(); ++b) { + for(std::list::iterator b = breakpoints_.begin(); b != breakpoints_.end(); ++b) { if ((*b)->is_break_now()){ current_breakpoint_ = (*b); show_gui(); current_breakpoint_ = breakpoint_ptr(); if ((*b)->is_one_time_only()) { - breakpoints_.erase(b); + b = breakpoints_.erase(b); } break; } @@ -272,8 +272,8 @@ class end_breakpoint : public base_breakpoint { virtual bool is_break_now() const { - const std::deque &call_stack = fdb_.get_call_stack(); - if ((call_stack.size() == 1) && (call_stack[0].evaluated()) ) { + const std::list &call_stack = fdb_.get_call_stack(); + if ((call_stack.size() == 1) && (call_stack.front().evaluated()) ) { return true; } return false; @@ -294,7 +294,7 @@ class step_in_breakpoint : public base_breakpoint { virtual bool is_break_now() const { - const std::deque &call_stack = fdb_.get_call_stack(); + const std::list &call_stack = fdb_.get_call_stack(); if (call_stack.empty() || call_stack.back().evaluated()) { return false; } @@ -317,7 +317,7 @@ class step_out_breakpoint : public base_breakpoint { virtual bool is_break_now() const { - const std::deque &call_stack = fdb_.get_call_stack(); + const std::list &call_stack = fdb_.get_call_stack(); if (call_stack.empty() || call_stack.back().evaluated()) { return false; } @@ -345,7 +345,7 @@ class next_breakpoint : public base_breakpoint { virtual bool is_break_now() const { - const std::deque &call_stack = fdb_.get_call_stack(); + const std::list &call_stack = fdb_.get_call_stack(); if (call_stack.empty() || call_stack.back().evaluated()) { return false; } diff --git a/src/formula/debugger.hpp b/src/formula/debugger.hpp index c262f97cb918..4e3a4f8b6c2a 100644 --- a/src/formula/debugger.hpp +++ b/src/formula/debugger.hpp @@ -23,7 +23,7 @@ #include "formula/variant.hpp" #include "formula/debugger_fwd.hpp" -#include +#include namespace game_logic { @@ -97,13 +97,13 @@ class formula_debugger { void check_breakpoints(); - const std::deque& get_call_stack() const; + const std::list& get_call_stack() const; const breakpoint_ptr get_current_breakpoint() const; - const std::deque& get_execution_trace() const; + const std::list& get_execution_trace() const; variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables); @@ -142,11 +142,11 @@ class formula_debugger { } private: - std::deque call_stack_; + std::list call_stack_; int counter_; breakpoint_ptr current_breakpoint_; - std::deque< breakpoint_ptr > breakpoints_; - std::deque execution_trace_; + std::list< breakpoint_ptr > breakpoints_; + std::list execution_trace_; int arg_number_extra_debug_info; std::string f_name_extra_debug_info;