Miscellaneous minor fixes based on cppcheck static analyzer

This commit is contained in:
ridiculousfish 2014-01-12 13:33:35 -08:00
parent 1130e4782d
commit 89069fdaa4
9 changed files with 22 additions and 34 deletions

View File

@ -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<path_list.size(); i++)
for (size_t i=0; i<path_list.size(); i++)
{
wcstring next = path_list.at(i);
wcstring path = next + L"/" + cmd + L".fish";

View File

@ -244,9 +244,6 @@ wcstring builtin_help_get(parser_t &parser, const wchar_t *name)
static void builtin_print_help(parser_t &parser, const wchar_t *cmd, wcstring &b)
{
int is_short = 0;
if (&b == &stderr_buffer)
{
stderr_buffer.append(parser.current_line());
@ -260,7 +257,7 @@ static void builtin_print_help(parser_t &parser, const wchar_t *cmd, wcstring &b
wchar_t *str = wcsdup(h.c_str());
if (str)
{
bool is_short = false;
if (&b == &stderr_buffer)
{
@ -279,7 +276,7 @@ static void builtin_print_help(parser_t &parser, const wchar_t *cmd, wcstring &b
int cut=0;
int i;
is_short = 1;
is_short = true;
/*
First move down 4 lines
@ -738,7 +735,6 @@ static int builtin_block(parser_t &parser, wchar_t **argv)
int scope=UNSET;
int erase = 0;
int argc=builtin_count_args(argv);
int type = (1<<EVENT_ANY);
woptind=0;
@ -836,7 +832,7 @@ static int builtin_block(parser_t &parser, wchar_t **argv)
block_t *block = parser.block_at_index(block_idx);
event_blockage_t eb = {};
eb.typemask = type;
eb.typemask = (1<<EVENT_ANY);
switch (scope)
{

View File

@ -143,17 +143,13 @@ static void write_part(const wchar_t *begin,
int cut_at_cursor,
int tokenize)
{
wcstring out;
wchar_t *buff;
size_t pos;
pos = get_cursor_pos()-(begin-get_buffer());
size_t pos = get_cursor_pos()-(begin-get_buffer());
if (tokenize)
{
buff = wcsndup(begin, end-begin);
wchar_t *buff = wcsndup(begin, end-begin);
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
out.clear();
wcstring out;
tokenizer_t tok(buff, TOK_ACCEPT_UNFINISHED);
for (; tok_has_next(&tok); tok_next(&tok))
{

View File

@ -290,7 +290,6 @@ static int builtin_complete(parser_t &parser, wchar_t **argv)
int result_mode=SHARED;
int remove = 0;
int authoritative = -1;
int flags = COMPLETE_AUTO_SPACE;
wcstring short_opt;
wcstring_list_t gnu_opt, old_opt;
@ -600,6 +599,8 @@ static int builtin_complete(parser_t &parser, wchar_t **argv)
}
else
{
int flags = COMPLETE_AUTO_SPACE;
if (remove)
{
builtin_complete_remove(cmd,

View File

@ -164,7 +164,6 @@ static int builtin_jobs(parser_t &parser, wchar_t **argv)
int found=0;
int mode=JOBS_DEFAULT;
int print_last = 0;
const job_t *j;
argc = builtin_count_args(argv);
woptind=0;
@ -305,7 +304,7 @@ static int builtin_jobs(parser_t &parser, wchar_t **argv)
return 1;
}
j = job_get_from_pid(pid);
const job_t *j = job_get_from_pid(pid);
if (j && !job_is_completed(j))
{

View File

@ -697,7 +697,6 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
/*
Slice mode
*/
size_t idx_count, val_count;
std::vector<long> 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)
{

View File

@ -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; i<trace_size; i++)
for (int i=0; i<trace_size; i++)
{
fwprintf(stderr, L"%s\n", messages[i]);
}
@ -830,19 +830,18 @@ void format_long_safe(wchar_t buff[128], long val)
void write_screen(const wcstring &msg, wcstring &buff)
{
const wchar_t *start, *pos;
int line_width = 0;
int tok_width = 0;
int screen_width = common_get_width();
if (screen_width)
{
start = pos = msg.c_str();
const wchar_t *start = msg.c_str();
const wchar_t *pos = start;
while (1)
{
int overflow = 0;
tok_width=0;
int tok_width=0;
/*
Tokenize on whitespace, and also calculate the width of the token

View File

@ -1484,7 +1484,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop
{
if (o->result_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;
}

View File

@ -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);
}
}