Miscellaneous cleanup and dead code removal

Noticed by cppcheck
This commit is contained in:
ridiculousfish 2016-02-19 15:45:12 -08:00
parent 8703c5bc00
commit 947f659f96
9 changed files with 32 additions and 41 deletions

View file

@ -1705,7 +1705,6 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base)
static bool builtin_echo_parse_numeric_sequence(const wchar_t *str, size_t *consumed, unsigned char *out_val) static bool builtin_echo_parse_numeric_sequence(const wchar_t *str, size_t *consumed, unsigned char *out_val)
{ {
bool success = false; bool success = false;
unsigned char val = 0; //resulting character
unsigned int start = 0; //the first character of the numeric part of the sequence unsigned int start = 0; //the first character of the numeric part of the sequence
unsigned int base = 0, max_digits = 0; unsigned int base = 0, max_digits = 0;
@ -1731,6 +1730,7 @@ static bool builtin_echo_parse_numeric_sequence(const wchar_t *str, size_t *cons
if (base != 0) if (base != 0)
{ {
unsigned int idx; unsigned int idx;
unsigned char val = 0; //resulting character
for (idx = start; idx < start + max_digits; idx++) for (idx = start; idx < start + max_digits; idx++)
{ {
unsigned int digit = builtin_echo_digit(str[idx], base); unsigned int digit = builtin_echo_digit(str[idx], base);

View file

@ -431,7 +431,6 @@ static int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv)
int retcode=0; int retcode=0;
int scope; int scope;
int slice=0; int slice=0;
int i;
const wchar_t *bad_char = NULL; const wchar_t *bad_char = NULL;
@ -793,7 +792,7 @@ static int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv)
else else
{ {
wcstring_list_t val; wcstring_list_t val;
for (i=w.woptind; i<argc; i++) for (int i=w.woptind; i<argc; i++)
val.push_back(argv[i]); val.push_back(argv[i]);
retcode = my_env_set(dest, val, scope, streams); retcode = my_env_set(dest, val, scope, streams);
} }

View file

@ -593,7 +593,6 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
{ {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
bool has_changed_old = has_changed_exported; bool has_changed_old = has_changed_exported;
bool has_changed_new = false;
int done=0; int done=0;
if (val && contains(key, L"PWD", L"HOME")) if (val && contains(key, L"PWD", L"HOME"))
@ -685,7 +684,7 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
else else
{ {
// Determine the node // Determine the node
bool has_changed_new = false;
env_node_t *preexisting_node = env_get_node(key); env_node_t *preexisting_node = env_get_node(key);
bool preexisting_entry_exportv = false; bool preexisting_entry_exportv = false;
if (preexisting_node != NULL) if (preexisting_node != NULL)
@ -1315,7 +1314,6 @@ static void update_export_array_if_necessary(bool recalc)
if (has_changed_exported) if (has_changed_exported)
{ {
std::map<wcstring, wcstring> vals; std::map<wcstring, wcstring> vals;
size_t i;
debug(4, L"env_export_arr() recalc"); debug(4, L"env_export_arr() recalc");
@ -1324,7 +1322,7 @@ static void update_export_array_if_necessary(bool recalc)
if (uvars()) if (uvars())
{ {
const wcstring_list_t uni = uvars()->get_names(true, false); const wcstring_list_t uni = uvars()->get_names(true, false);
for (i=0; i<uni.size(); i++) for (size_t i=0; i<uni.size(); i++)
{ {
const wcstring &key = uni.at(i); const wcstring &key = uni.at(i);
const env_var_t val = uvars()->get(key); const env_var_t val = uvars()->get(key);

View file

@ -1210,11 +1210,11 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t
{ {
int err = errno; int err = errno;
report_error(err, L"Unable to memory map shared memory object with path '%s'", path); report_error(err, L"Unable to memory map shared memory object with path '%s'", path);
region = NULL; this->region = NULL;
} }
else else
{ {
region = static_cast<universal_notifier_shmem_t*>(addr); this->region = static_cast<universal_notifier_shmem_t*>(addr);
} }
} }

View file

@ -1363,13 +1363,12 @@ struct interval
static int bisearch(wchar_t ucs, const struct interval *table, int max) static int bisearch(wchar_t ucs, const struct interval *table, int max)
{ {
int min = 0; int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last) if (ucs < table[0].first || ucs > table[max].last)
return 0; return 0;
while (max >= min) while (max >= min)
{ {
mid = (min + max) / 2; int mid = (min + max) / 2;
if (ucs > table[mid].last) if (ucs > table[mid].last)
min = mid + 1; min = mid + 1;
else if (ucs < table[mid].first) else if (ucs < table[mid].first)

View file

@ -536,7 +536,6 @@ parse_execution_result_t parse_execution_context_t::run_for_statement(const pars
parse_execution_result_t parse_execution_context_t::run_switch_statement(const parse_node_t &statement) parse_execution_result_t parse_execution_context_t::run_switch_statement(const parse_node_t &statement)
{ {
assert(statement.type == symbol_switch_statement); assert(statement.type == symbol_switch_statement);
const parse_node_t *matching_case_item = NULL;
parse_execution_result_t result = parse_execution_success; parse_execution_result_t result = parse_execution_success;
@ -590,6 +589,7 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list); const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list);
/* Loop while we don't have a match but do have more of the list */ /* Loop while we don't have a match but do have more of the list */
const parse_node_t *matching_case_item = NULL;
while (matching_case_item == NULL && case_item_list != NULL) while (matching_case_item == NULL && case_item_list != NULL)
{ {
if (should_cancel_execution(sb)) if (should_cancel_execution(sb))
@ -990,7 +990,6 @@ parse_execution_result_t parse_execution_context_t::determine_arguments(const pa
{ {
this->report_errors(errors); this->report_errors(errors);
return parse_execution_errored; return parse_execution_errored;
break;
} }
case EXPAND_WILDCARD_NO_MATCH: case EXPAND_WILDCARD_NO_MATCH:

View file

@ -112,7 +112,16 @@ public:
wcstring describe(void) const; wcstring describe(void) const;
/* Constructor */ /* Constructor */
explicit parse_node_t(parse_token_type_t ty) : source_start(SOURCE_OFFSET_INVALID), source_length(0), parent(NODE_OFFSET_INVALID), child_start(0), child_count(0), type(ty), flags(0), tag(0) explicit parse_node_t(parse_token_type_t ty) :
source_start(SOURCE_OFFSET_INVALID),
source_length(0),
parent(NODE_OFFSET_INVALID),
child_start(0),
child_count(0),
type(ty),
keyword(parse_keyword_none),
flags(0),
tag(0)
{ {
} }

View file

@ -139,7 +139,7 @@ bool wildcard_has(const wcstring &str, bool internal)
\param wc The wildcard. \param wc The wildcard.
\param is_first Whether files beginning with dots should not be matched against wildcards. \param is_first Whether files beginning with dots should not be matched against wildcards.
*/ */
static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const wchar_t *wc, bool leading_dots_fail_to_match, bool is_first, enum fuzzy_match_type_t max_type) static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const wchar_t *wc, bool leading_dots_fail_to_match, bool is_first)
{ {
if (*str == 0 && *wc==0) if (*str == 0 && *wc==0)
{ {
@ -154,13 +154,6 @@ static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const
return wcscmp(str, wc) ? fuzzy_match_none : fuzzy_match_exact; return wcscmp(str, wc) ? fuzzy_match_none : fuzzy_match_exact;
} }
/* Hackish fuzzy match support */
if (! wildcard_has(wc, true))
{
const string_fuzzy_match_t match = string_fuzzy_match_string(wc, str);
return (match.type <= max_type ? match.type : fuzzy_match_none);
}
if (*wc == ANY_STRING || *wc == ANY_STRING_RECURSIVE) if (*wc == ANY_STRING || *wc == ANY_STRING_RECURSIVE)
{ {
/* Ignore hidden file */ /* Ignore hidden file */
@ -178,7 +171,7 @@ static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const
/* Try all submatches */ /* Try all submatches */
do do
{ {
enum fuzzy_match_type_t subresult = wildcard_match_internal(str, wc+1, leading_dots_fail_to_match, false, max_type); enum fuzzy_match_type_t subresult = wildcard_match_internal(str, wc+1, leading_dots_fail_to_match, false);
if (subresult != fuzzy_match_none) if (subresult != fuzzy_match_none)
{ {
return subresult; return subresult;
@ -201,11 +194,11 @@ static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const
return fuzzy_match_none; return fuzzy_match_none;
} }
return wildcard_match_internal(str+1, wc+1, leading_dots_fail_to_match, false, max_type); return wildcard_match_internal(str+1, wc+1, leading_dots_fail_to_match, false);
} }
else if (*wc == *str) else if (*wc == *str)
{ {
return wildcard_match_internal(str+1, wc+1, leading_dots_fail_to_match, false, max_type); return wildcard_match_internal(str+1, wc+1, leading_dots_fail_to_match, false);
} }
return fuzzy_match_none; return fuzzy_match_none;
@ -237,14 +230,19 @@ static wcstring resolve_description(wcstring *completion, const wchar_t *explici
} }
} }
/* A transient parameter pack needed by wildcard_complete.f */ /* A transient parameter pack needed by wildcard_complete. */
struct wc_complete_pack_t struct wc_complete_pack_t
{ {
const wcstring &orig; // the original string, transient const wcstring &orig; // the original string, transient
const wchar_t *desc; // literal description const wchar_t *desc; // literal description
wcstring(*desc_func)(const wcstring &); // function for generating descriptions wcstring(*desc_func)(const wcstring &); // function for generating descriptions
expand_flags_t expand_flags; expand_flags_t expand_flags;
wc_complete_pack_t(const wcstring &str) : orig(str) {} wc_complete_pack_t(const wcstring &str, const wchar_t *des, wcstring(*df)(const wcstring &), expand_flags_t fl) :
orig(str),
desc(des),
desc_func(df),
expand_flags(fl)
{}
}; };
/* Weirdly specific and non-reusable helper function that makes its one call site much clearer */ /* Weirdly specific and non-reusable helper function that makes its one call site much clearer */
@ -412,24 +410,16 @@ bool wildcard_complete(const wcstring &str,
{ {
// Note out may be NULL // Note out may be NULL
assert(wc != NULL); assert(wc != NULL);
wc_complete_pack_t params(str); wc_complete_pack_t params(str, desc, desc_func, expand_flags);
params.desc = desc;
params.desc_func = desc_func;
params.expand_flags = expand_flags;
return wildcard_complete_internal(str.c_str(), wc, params, flags, out, true /* first call */); return wildcard_complete_internal(str.c_str(), wc, params, flags, out, true /* first call */);
} }
bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match) bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match)
{ {
enum fuzzy_match_type_t match = wildcard_match_internal(str.c_str(), wc.c_str(), leading_dots_fail_to_match, true /* first */, fuzzy_match_exact); enum fuzzy_match_type_t match = wildcard_match_internal(str.c_str(), wc.c_str(), leading_dots_fail_to_match, true /* first */);
return match != fuzzy_match_none; return match != fuzzy_match_none;
} }
enum fuzzy_match_type_t wildcard_match_fuzzy(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match, enum fuzzy_match_type_t max_type)
{
return wildcard_match_internal(str.c_str(), wc.c_str(), leading_dots_fail_to_match, true /* first */, max_type);
}
/** /**
Obtain a description string for the file specified by the filename. Obtain a description string for the file specified by the filename.
@ -827,7 +817,7 @@ class wildcard_expander_t
public: public:
wildcard_expander_t(const wcstring pref, const wcstring &orig_base, const wchar_t *orig_wc, expand_flags_t f, std::vector<completion_t> *r) : wildcard_expander_t(const wcstring &pref, const wcstring &orig_base, const wchar_t *orig_wc, expand_flags_t f, std::vector<completion_t> *r) :
prefix(pref), prefix(pref),
original_base(orig_base), original_base(orig_base),
original_wildcard(orig_wc), original_wildcard(orig_wc),

View file

@ -77,9 +77,6 @@ int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory
*/ */
bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match = false); bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match = false);
/* Like wildcard_match, but returns a fuzzy match type */
enum fuzzy_match_type_t wildcard_match_fuzzy(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match = false, enum fuzzy_match_type_t max_type = fuzzy_match_none);
/** Check if the specified string contains wildcards */ /** Check if the specified string contains wildcards */
bool wildcard_has(const wcstring &, bool internal); bool wildcard_has(const wcstring &, bool internal);
bool wildcard_has(const wchar_t *, bool internal); bool wildcard_has(const wchar_t *, bool internal);