From c35b35e4f81c4376d6a79e4365641049a8c4d026 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 11 May 2014 11:53:03 -0600 Subject: [PATCH] Fix issues discovered while evaluating pvs-studio --- include/chaiscript/language/chaiscript_common.hpp | 6 +++--- include/chaiscript/language/chaiscript_eval.hpp | 6 +++--- include/chaiscript/language/chaiscript_parser.hpp | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index a628d9b..e0768c5 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -404,7 +404,7 @@ namespace chaiscript oss << text; - for (unsigned int j = 0; j < this->children.size(); ++j) { + for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->pretty_print(); } @@ -413,13 +413,13 @@ namespace chaiscript /// Prints the contents of an AST node, including its children, recursively - std::string to_string(std::string t_prepend = "") { + std::string to_string(const std::string &t_prepend = "") { std::ostringstream oss; oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") " << this->text << " : " << this->start.line << ", " << this->start.column << std::endl; - for (unsigned int j = 0; j < this->children.size(); ++j) { + for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->to_string(t_prepend + " "); } return oss.str(); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 076c7de..d22d765 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -258,7 +258,7 @@ namespace chaiscript { std::ostringstream oss; - for (unsigned int j = 0; j < this->children.size(); ++j) { + for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->pretty_print(); if (j == 0) @@ -323,7 +323,7 @@ namespace chaiscript virtual std::string pretty_print() const { std::ostringstream oss; - for (unsigned int j = 0; j < this->children.size(); ++j) { + for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->pretty_print(); if (j == 0) @@ -1248,7 +1248,7 @@ namespace chaiscript assert(end_point > 0); end_point = this->children.size() - 1; } - for (unsigned int i = 1; i < end_point; ++i) { + for (size_t i = 1; i < end_point; ++i) { chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss); AST_NodePtr catch_block = this->children[i]; diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 8acd641..01f70fa 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -212,7 +212,7 @@ namespace chaiscript * Shows the current stack of matched ast_nodes */ void show_match_stack() { - for (unsigned int i = 0; i < m_match_stack.size(); ++i) { + for (size_t i = 0; i < m_match_stack.size(); ++i) { //debug_print(match_stack[i]); std::cout << m_match_stack[i]->to_string(); } @@ -1109,11 +1109,11 @@ namespace chaiscript */ bool Keyword_(const char *t_s) { bool retval = false; - int len = static_cast(strlen(t_s)); + size_t len = strlen(t_s); - if ((m_input_end - m_input_pos) >= len) { + if ((m_input_end - m_input_pos) >= static_cast::type>(len)) { std::string::const_iterator tmp = m_input_pos; - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (*tmp != t_s[i]) { return false; } @@ -1157,11 +1157,11 @@ namespace chaiscript */ bool Symbol_(const char *t_s) { bool retval = false; - int len = static_cast(strlen(t_s)); + size_t len = strlen(t_s); - if ((m_input_end - m_input_pos) >= len) { + if ((m_input_end - m_input_pos) >= static_cast::type>(len)) { std::string::const_iterator tmp = m_input_pos; - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (*tmp != t_s[i]) { return false; }