From 89069fdaa4fff2f8b703fef0be260eb4d4c2ed9b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 12 Jan 2014 13:33:35 -0800 Subject: [PATCH] Miscellaneous minor fixes based on cppcheck static analyzer --- autoload.cpp | 3 +-- builtin.cpp | 10 +++------- builtin_commandline.cpp | 10 +++------- builtin_complete.cpp | 3 ++- builtin_jobs.cpp | 3 +-- builtin_set.cpp | 7 +++---- common.cpp | 11 +++++------ complete.cpp | 4 ++-- parse_tree.cpp | 5 ++--- 9 files changed, 22 insertions(+), 34 deletions(-) diff --git a/autoload.cpp b/autoload.cpp index 3470ecae6..e5d2334df 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -195,7 +195,6 @@ autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcs bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list) { /* Note that we are NOT locked in this function! */ - size_t i; bool reloaded = 0; /* Try using a cached function. If we really want the function to be loaded, require that it be really loaded. If we're not reloading, allow stale functions. */ @@ -276,7 +275,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_ if (! has_script_source) { /* Iterate over path searching for suitable completion files */ - for (i=0; i indexes; wcstring_list_t result; @@ -713,9 +712,9 @@ static int builtin_set(parser_t &parser, wchar_t **argv) retcode = 1; break; } - - val_count = argc-woptind-1; - idx_count = indexes.size(); + + size_t idx_count = indexes.size(); + size_t val_count = argc-woptind-1; if (!erase) { diff --git a/common.cpp b/common.cpp index a36f4169b..a600432b0 100644 --- a/common.cpp +++ b/common.cpp @@ -105,7 +105,7 @@ void show_stackframe() return; void *trace[32]; - int i, trace_size = 0; + int trace_size = 0; trace_size = backtrace(trace, 32); char **messages = backtrace_symbols(trace, trace_size); @@ -113,7 +113,7 @@ void show_stackframe() if (messages) { debug(0, L"Backtrace:"); - for (i=0; iresult_mode & NO_COMMON) use_common = false; if (o->result_mode & NO_FILES) use_files = false; - complete_from_args(str, o->comp.c_str(), o->localized_desc(), o->flags); + complete_from_args(str, o->comp, o->localized_desc(), o->flags); } } @@ -1697,7 +1697,7 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) desc = format_string(COMPLETE_VAR_DESC_VAL, value.c_str()); } - append_completion(this->completions, comp.c_str(), desc.c_str(), flags, match); + append_completion(this->completions, comp, desc, flags, match); res = true; } diff --git a/parse_tree.cpp b/parse_tree.cpp index 5134379d5..ee401a451 100644 --- a/parse_tree.cpp +++ b/parse_tree.cpp @@ -765,7 +765,7 @@ void parse_ll_t::parse_error(const wchar_t *expected, parse_token_t token) fatal_errored = true; if (this->should_generate_error_messages) { - wcstring desc = token_type_description(token.type); + wcstring desc = token.user_presentable_description(); this->parse_error(token, parse_error_generic, L"Expected a %ls, instead got a token of type %ls", expected, desc.c_str()); } } @@ -881,8 +881,7 @@ bool parse_ll_t::top_node_handle_terminal_types(parse_token_t token) } else { - const wcstring expected = token_type_description(stack_top.type); - const wcstring actual = token_type_description(token.type); + const wcstring expected = stack_top.user_presentable_description(); this->parse_error(expected.c_str(), token); } }