From e286b9a9aaed444fc240e72f1d595de18fea720d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 1 May 2015 07:22:43 -0600 Subject: [PATCH] Never access data after moving it! --- .../chaiscript/language/chaiscript_eval.hpp | 4 +-- .../chaiscript/language/chaiscript_parser.hpp | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index f58aaca..15cfb8e 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -998,7 +998,7 @@ namespace chaiscript public: Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector t_children) : AST_Node(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children)) - { assert(t_children.size() == 2); } + { assert(children.size() == 2); /* how many children does it have? */ } virtual ~Case_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE { @@ -1014,7 +1014,7 @@ namespace chaiscript public: Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector t_children) : AST_Node(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children)) - { assert(t_children.size() == 1); } + { assert(children.size() == 1); } virtual ~Default_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE { chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 67891f5..89dd9df 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -719,7 +719,8 @@ namespace chaiscript if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) { if (Hex_()) { std::string match(start, m_input_pos); - m_match_stack.emplace_back(make_node(std::move(match), prev_line, prev_col, buildInt(std::hex, match))); + auto bv = buildInt(std::hex, match); + m_match_stack.emplace_back(make_node(std::move(match), prev_line, prev_col, std::move(bv))); return true; } @@ -737,30 +738,34 @@ namespace chaiscript ++pos; } - Boxed_Value i; - if (match.length() <= sizeof(int) * 8) - { - i = const_var(static_cast(temp_int)); - } else { - i = const_var(temp_int); - } + Boxed_Value i = [&](){ + if (match.length() <= sizeof(int) * 8) + { + return const_var(static_cast(temp_int)); + } else { + return const_var(temp_int); + } + }(); m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, std::move(i))); return true; } if (Float_()) { std::string match(start, m_input_pos); - m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, buildFloat(match))); + auto bv = buildFloat(match); + m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, std::move(bv))); return true; } else { IntSuffix_(); std::string match(start, m_input_pos); if (!match.empty() && (match[0] == '0')) { - m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, buildInt(std::oct, match))); + auto bv = buildInt(std::oct, match); + m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, std::move(bv))); } else { - m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, buildInt(std::dec, match))); + auto bv = buildInt(std::dec, match); + m_match_stack.push_back(make_node(std::move(match), prev_line, prev_col, std::move(bv))); } return true; }