lint: avoid branching statement as last in loop

This commit is contained in:
Kurtis Rader 2016-11-01 20:00:09 -07:00
parent c10952c354
commit 60c47deca9
3 changed files with 59 additions and 56 deletions

View file

@ -233,7 +233,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
if (!has_script_source) { if (!has_script_source) {
// Iterate over path searching for suitable completion files. // Iterate over path searching for suitable completion files.
for (size_t i = 0; i < path_list.size(); i++) { for (size_t i = 0; i < path_list.size() && !found_file; i++) {
wcstring next = path_list.at(i); wcstring next = path_list.at(i);
wcstring path = next + L"/" + cmd + L".fish"; wcstring path = next + L"/" + cmd + L".fish";
@ -242,7 +242,6 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
continue; continue;
} }
found_file = true;
// Now we're actually going to take the lock. // Now we're actually going to take the lock.
scoped_lock locker(lock); scoped_lock locker(lock);
autoload_function_t *func = this->get_node(cmd); autoload_function_t *func = this->get_node(cmd);
@ -279,7 +278,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
// Unconditionally record our access time. // Unconditionally record our access time.
func->access = access; func->access = access;
break; found_file = true;
} }
// If no file or builtin script was found we insert a placeholder function. Later we only // If no file or builtin script was found we insert a placeholder function. Later we only

View file

@ -685,9 +685,12 @@ class regex_replacer_t : public string_replacer_t {
regex(argv0, pattern, opts.ignore_case, streams), regex(argv0, pattern, opts.ignore_case, streams),
replacement(interpret_escapes(replacement_)) {} replacement(interpret_escapes(replacement_)) {}
bool replace_matches(const wchar_t *arg) { bool replace_matches(const wchar_t *arg);
// A return value of true means all is well (even if no replacements were performed), false };
// indicates an unrecoverable error.
/// A return value of true means all is well (even if no replacements were performed), false
/// indicates an unrecoverable error.
bool regex_replacer_t::replace_matches(const wchar_t *arg) {
if (regex.code == 0) { if (regex.code == 0) {
// pcre2_compile() failed // pcre2_compile() failed
return false; return false;
@ -698,8 +701,10 @@ class regex_replacer_t : public string_replacer_t {
size_t arglen = wcslen(arg); size_t arglen = wcslen(arg);
PCRE2_SIZE bufsize = (arglen == 0) ? 16 : 2 * arglen; PCRE2_SIZE bufsize = (arglen == 0) ? 16 : 2 * arglen;
wchar_t *output = (wchar_t *)malloc(sizeof(wchar_t) * bufsize); wchar_t *output = (wchar_t *)malloc(sizeof(wchar_t) * bufsize);
int pcre2_rc = 0; int pcre2_rc;
for (;;) {
bool done = false;
while (!done) {
if (output == NULL) { if (output == NULL) {
DIE_MEM(); DIE_MEM();
} }
@ -711,13 +716,13 @@ class regex_replacer_t : public string_replacer_t {
PCRE2_SPTR(replacement.c_str()), PCRE2_ZERO_TERMINATED, PCRE2_SPTR(replacement.c_str()), PCRE2_ZERO_TERMINATED,
(PCRE2_UCHAR *)output, &outlen); (PCRE2_UCHAR *)output, &outlen);
if (pcre2_rc == PCRE2_ERROR_NOMEMORY && bufsize < outlen) { if (pcre2_rc != PCRE2_ERROR_NOMEMORY || bufsize >= outlen) {
done = true;
} else {
bufsize = outlen; bufsize = outlen;
// cppcheck-suppress memleakOnRealloc // cppcheck-suppress memleakOnRealloc
output = (wchar_t *)realloc(output, sizeof(wchar_t) * bufsize); output = (wchar_t *)realloc(output, sizeof(wchar_t) * bufsize);
continue;
} }
break;
} }
bool rc = true; bool rc = true;
@ -736,7 +741,6 @@ class regex_replacer_t : public string_replacer_t {
free(output); free(output);
return rc; return rc;
} }
};
static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) { static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
const wchar_t *short_options = L"aiqr"; const wchar_t *short_options = L"aiqr";

View file

@ -1386,7 +1386,7 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
const parse_node_t *result = NULL; const parse_node_t *result = NULL;
// Find nodes of the given type in the tree, working backwards. // Find nodes of the given type in the tree, working backwards.
const size_t len = this->size(); const size_t len = this->size();
for (size_t idx = 0; idx < len; idx++) { for (size_t idx = 0; idx < len && result == NULL; idx++) {
const parse_node_t &node = this->at(idx); const parse_node_t &node = this->at(idx);
// Types must match. // Types must match.
@ -1400,8 +1400,8 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
// Found it. // Found it.
result = &node; result = &node;
break;
} }
return result; return result;
} }