lint cleanup: parameter reassignment

This commit is contained in:
Kurtis Rader 2016-10-20 18:53:31 -07:00
parent 345950ac1b
commit 00303ed07f
14 changed files with 33 additions and 52 deletions

View file

@ -412,7 +412,7 @@ static int builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int u
}
int res = 0;
if (mode == NULL) mode = DEFAULT_BIND_MODE;
if (mode == NULL) mode = DEFAULT_BIND_MODE; //!OCLINT(parameter reassignment)
while (*seq) {
if (use_terminfo) {

View file

@ -165,16 +165,14 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs
}
streams.out.append(out);
free(buff);
} else {
if (cut_at_cursor) {
end = begin + pos;
streams.out.append(begin, pos);
} else {
streams.out.append(begin, end - begin);
}
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
streams.out.append(begin, end - begin);
streams.out.append(L"\n");
streams.out.push_back(L'\n');
}
}

View file

@ -159,7 +159,6 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope,
static int parse_index(std::vector<long> &indexes, const wchar_t *src, const wchar_t *name,
size_t var_count, io_streams_t &streams) {
size_t len;
int count = 0;
const wchar_t *src_orig = src;
@ -167,9 +166,7 @@ static int parse_index(std::vector<long> &indexes, const wchar_t *src, const wch
return 0;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_')) {
src++;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_')) src++;
if (*src != L'[') {
streams.err.append_format(_(BUILTIN_SET_ARG_COUNT), L"set");
@ -177,7 +174,6 @@ static int parse_index(std::vector<long> &indexes, const wchar_t *src, const wch
}
len = src - src_orig;
if ((wcsncmp(src_orig, name, len) != 0) || (wcslen(name) != (len))) {
streams.err.append_format(
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"), L"set",
@ -186,37 +182,29 @@ static int parse_index(std::vector<long> &indexes, const wchar_t *src, const wch
}
src++;
while (iswspace(*src)) {
src++;
}
while (iswspace(*src)) src++;
while (*src != L']') {
wchar_t *end;
long l_ind;
errno = 0;
l_ind = wcstol(src, &end, 10);
if (end == src || errno) {
streams.err.append_format(_(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return 0;
}
if (l_ind < 0) {
l_ind = var_count + l_ind + 1;
}
if (l_ind < 0) l_ind = var_count + l_ind + 1;
src = end;
src = end; //!OCLINT(parameter reassignment)
if (*src == L'.' && *(src + 1) == L'.') {
src += 2;
long l_ind2 = wcstol(src, &end, 10);
if (end == src || errno) {
return 1;
}
src = end;
src = end; //!OCLINT(parameter reassignment)
if (l_ind2 < 0) {
l_ind2 = var_count + l_ind2 + 1;
@ -231,6 +219,7 @@ static int parse_index(std::vector<long> &indexes, const wchar_t *src, const wch
indexes.push_back(l_ind);
count++;
}
while (iswspace(*src)) src++;
}

View file

@ -107,6 +107,7 @@ demangled_backtrace(int max_frames, int skip_levels) {
void __attribute__((noinline))
show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
ASSERT_IS_NOT_FORKED_CHILD();
if (frame_count < 1) return;
// TODO: Decide if this is still needed. I'm commenting it out because it caused me some grief
// while trying to debug a test failure. And the tests run just fine without spurious failures
@ -115,7 +116,6 @@ show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
// Hack to avoid showing backtraces in the tester.
// if (program_name && !wcscmp(program_name, L"(ignore)")) return;
if (frame_count < 1) frame_count = 999;
debug_shared(msg_level, L"Backtrace:");
std::vector<wcstring> bt = demangled_backtrace(frame_count, skip_levels + 2);
for (int i = 0; (size_t)i < bt.size(); i++) {

View file

@ -258,7 +258,7 @@ extern bool has_working_tty_timestamps;
#define contains(str, ...) contains_internal(str, 0, __VA_ARGS__, NULL)
/// Print a stack trace to stderr.
void show_stackframe(const wchar_t msg_level, int frame_count = -1, int skip_levels = 0);
void show_stackframe(const wchar_t msg_level, int frame_count = 100, int skip_levels = 0);
/// Read a line from the stream f into the string. Returns the number of bytes read or -1 on
/// failure.

View file

@ -521,7 +521,7 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
// Zero element arrays are internaly not coded as null but as this placeholder string.
if (!val) {
val = ENV_NULL;
val = ENV_NULL; //!OCLINT(parameter reassignment)
}
if (var_mode & ENV_UNIVERSAL) {
@ -569,7 +569,8 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
if ((var_mode & (ENV_EXPORT | ENV_UNEXPORT)) == 0) {
// use existing entry's exportv
var_mode = preexisting_entry_exportv ? ENV_EXPORT : 0;
var_mode =
preexisting_entry_exportv ? ENV_EXPORT : 0; //!OCLINT(parameter reassignment)
}
} else {
if (!get_proc_had_barrier()) {

View file

@ -1460,7 +1460,7 @@ universal_notifier_t &universal_notifier_t::default_notifier() {
universal_notifier_t *universal_notifier_t::new_notifier_for_strategy(
universal_notifier_t::notifier_strategy_t strat, const wchar_t *test_path) {
if (strat == strategy_default) {
strat = resolve_default_strategy();
strat = resolve_default_strategy(); //!OCLINT(parameter reassignment)
}
switch (strat) {
case strategy_shmem_polling: {

View file

@ -353,7 +353,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) {
if (ucs > table[mid].last)
min = mid + 1;
else if (ucs < table[mid].first)
max = mid - 1;
max = mid - 1; //!OCLINT(parameter reassignment)
else
return 1;
}

View file

@ -312,13 +312,10 @@ int writech(wint_t ch) {
if (ch >= ENCODE_DIRECT_BASE && ch < ENCODE_DIRECT_BASE + 256) {
buff[0] = ch - ENCODE_DIRECT_BASE;
len = 1;
} else if (MB_CUR_MAX == 1) // single-byte locale (C/POSIX/ISO-8859)
{
} else if (MB_CUR_MAX == 1) {
// single-byte locale (C/POSIX/ISO-8859)
// If `wc` contains a wide character we emit a question-mark.
if (ch & ~0xFF) {
ch = '?';
}
buff[0] = ch;
buff[0] = ch & ~0xFF ? '?' : ch;
len = 1;
} else {
mbstate_t state = {};

View file

@ -88,13 +88,11 @@ size_t parse_util_get_offset(const wcstring &str, int line, long line_offset) {
size_t off2 = parse_util_get_offset_from_line(buff, line + 1);
if (off == (size_t)-1) return (size_t)-1;
if (off2 == (size_t)-1) off2 = wcslen(buff) + 1;
if (line_offset < 0) line_offset = 0;
if (line_offset < 0) line_offset = 0; //!OCLINT(parameter reassignment)
if ((size_t)line_offset >= off2 - off - 1) {
line_offset = off2 - off - 1;
line_offset = off2 - off - 1; //!OCLINT(parameter reassignment)
}
return off + line_offset;
@ -763,10 +761,9 @@ static int parser_is_pipe_forbidden(const wcstring &word) {
bool parse_util_argument_is_help(const wchar_t *s, int min_match) {
CHECK(s, 0);
size_t len = wcslen(s);
min_match = maxi(min_match, 3);
min_match = maxi(min_match, 3); //!OCLINT(parameter reassignment)
return wcscmp(L"-h", s) == 0 || (len >= (size_t)min_match && (wcsncmp(L"--help", s, len) == 0));
}

View file

@ -713,9 +713,7 @@ bool parser_t::detect_errors_in_argument_list(const wcstring &arg_list_src, wcst
parse_error_list_t errors;
// Use empty string for the prefix if it's NULL.
if (prefix == NULL) {
prefix = L"";
}
if (!prefix) prefix = L""; //!OCLINT(parameter reassignment)
// Parse the string as an argument list.
parse_node_tree_t tree;

View file

@ -135,8 +135,8 @@ static void set_command_line_and_position(editable_line_t *el, const wcstring &n
void editable_line_t::insert_string(const wcstring &str, size_t start, size_t len) {
// Clamp the range to something valid.
size_t string_length = str.size();
start = mini(start, string_length);
len = mini(len, string_length - start);
start = mini(start, string_length); //!OCLINT(parameter reassignment)
len = mini(len, string_length - start); //!OCLINT(parameter reassignment)
this->text.insert(this->position, str, start, len);
this->position += len;
}
@ -1898,7 +1898,7 @@ static void reader_set_buffer_maintaining_pager(const wcstring &b, size_t pos) {
data->command_line_changed(&data->command_line);
// Don't set a position past the command line length.
if (pos > command_line_len) pos = command_line_len;
if (pos > command_line_len) pos = command_line_len; //!OCLINT(parameter reassignment)
update_buff_pos(&data->command_line, pos);

View file

@ -47,8 +47,8 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) {
secondary_diff = (aend - a) - (bend - b);
a = aend - 1;
b = bend - 1;
a = aend - 1; //!OCLINT(parameter reassignment)
b = bend - 1; //!OCLINT(parameter reassignment)
} else {
int diff = towlower(*a) - towlower(*b);
if (diff != 0) return diff > 0 ? 2 : -2;

View file

@ -161,8 +161,9 @@ const wchar_t *wgetopter_t::_wgetopt_initialize(const wchar_t *optstring) {
} else if (optstring[0] == '+') {
ordering = REQUIRE_ORDER;
++optstring;
} else
} else {
ordering = PERMUTE;
}
return optstring;
}
@ -211,7 +212,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
const struct woption *longopts, int *longind, int long_only) {
woptarg = NULL;
if (woptind == 0) optstring = _wgetopt_initialize(optstring);
if (woptind == 0) optstring = _wgetopt_initialize(optstring); //!OCLINT(parameter reassignment)
if (nextchar == NULL || *nextchar == '\0') {
// Advance to the next ARGV-element.