lint: Use early exit/continue

This commit is contained in:
Kurtis Rader 2016-10-30 21:05:27 -07:00
parent 520f810bf9
commit 2c38978115

View file

@ -197,7 +197,10 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
int ret = parse_util_locate_brackets_of_type(valid_range_start, &bracket_range_begin, int ret = parse_util_locate_brackets_of_type(valid_range_start, &bracket_range_begin,
&bracket_range_end, accept_incomplete, open_type, &bracket_range_end, accept_incomplete, open_type,
close_type); close_type);
if (ret > 0) { if (ret <= 0) {
return ret;
}
// The command substitutions must not be NULL and must be in the valid pointer range, and // The command substitutions must not be NULL and must be in the valid pointer range, and
// the end must be bigger than the beginning. // the end must be bigger than the beginning.
assert(bracket_range_begin != NULL && bracket_range_begin >= valid_range_start && assert(bracket_range_begin != NULL && bracket_range_begin >= valid_range_start &&
@ -216,7 +219,6 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
// Update the inout_cursor_offset. Note this may cause it to exceed str.size(), though // Update the inout_cursor_offset. Note this may cause it to exceed str.size(), though
// overflow is not likely. // overflow is not likely.
*inout_cursor_offset = 1 + *out_end; *inout_cursor_offset = 1 + *out_end;
}
return ret; return ret;
} }
@ -921,8 +923,12 @@ static parser_test_error_bits_t detect_dollar_cmdsub_errors(size_t arg_src_offse
parse_error_list_t *out_errors) { parse_error_list_t *out_errors) {
parser_test_error_bits_t result_bits = 0; parser_test_error_bits_t result_bits = 0;
wcstring unescaped_arg_src; wcstring unescaped_arg_src;
if (unescape_string(arg_src, &unescaped_arg_src, UNESCAPE_SPECIAL) &&
!unescaped_arg_src.empty()) { if (!unescape_string(arg_src, &unescaped_arg_src, UNESCAPE_SPECIAL) ||
unescaped_arg_src.empty()) {
return result_bits;
}
wchar_t last = unescaped_arg_src.at(unescaped_arg_src.size() - 1); wchar_t last = unescaped_arg_src.at(unescaped_arg_src.size() - 1);
if (last == VARIABLE_EXPAND) { if (last == VARIABLE_EXPAND) {
result_bits |= PARSER_TEST_ERROR; result_bits |= PARSER_TEST_ERROR;
@ -938,7 +944,7 @@ static parser_test_error_bits_t detect_dollar_cmdsub_errors(size_t arg_src_offse
ERROR_BAD_VAR_SUBCOMMAND1, truncate_string(subcommand_first_token).c_str()); ERROR_BAD_VAR_SUBCOMMAND1, truncate_string(subcommand_first_token).c_str());
} }
} }
}
return result_bits; return result_bits;
} }
@ -1023,9 +1029,11 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t
// Check for invalid variable expansions. // Check for invalid variable expansions.
const size_t unesc_size = unesc.size(); const size_t unesc_size = unesc.size();
for (size_t idx = 0; idx < unesc_size; idx++) { for (size_t idx = 0; idx < unesc_size; idx++) {
if (unesc.at(idx) == VARIABLE_EXPAND || unesc.at(idx) == VARIABLE_EXPAND_SINGLE) { if (unesc.at(idx) != VARIABLE_EXPAND && unesc.at(idx) != VARIABLE_EXPAND_SINGLE) {
wchar_t next_char = idx + 1 < unesc_size ? unesc.at(idx + 1) : L'\0'; continue;
}
wchar_t next_char = idx + 1 < unesc_size ? unesc.at(idx + 1) : L'\0';
if (next_char != VARIABLE_EXPAND && next_char != VARIABLE_EXPAND_SINGLE && if (next_char != VARIABLE_EXPAND && next_char != VARIABLE_EXPAND_SINGLE &&
!wcsvarchr(next_char)) { !wcsvarchr(next_char)) {
err = 1; err = 1;
@ -1042,7 +1050,6 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t
} }
} }
} }
}
return err; return err;
} }
@ -1147,33 +1154,38 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
assert(next_job_list != NULL); assert(next_job_list != NULL);
const parse_node_t *next_job = const parse_node_t *next_job =
node_tree.next_node_in_node_list(*next_job_list, symbol_job, NULL); node_tree.next_node_in_node_list(*next_job_list, symbol_job, NULL);
if (next_job != NULL) { if (next_job == NULL) {
break;
}
const parse_node_t *next_statement = const parse_node_t *next_statement =
node_tree.get_child(*next_job, 0, symbol_statement); node_tree.get_child(*next_job, 0, symbol_statement);
if (next_statement != NULL) { if (next_statement == NULL) {
break;
}
const parse_node_t *spec_statement = const parse_node_t *spec_statement =
node_tree.get_child(*next_statement, 0); node_tree.get_child(*next_statement, 0);
if (spec_statement && if (!spec_statement ||
spec_statement->type == symbol_boolean_statement) { spec_statement->type != symbol_boolean_statement) {
switch (parse_node_tree_t::statement_boolean_type( break;
*spec_statement)) { }
// These are not allowed.
case parse_bool_and: switch (parse_node_tree_t::statement_boolean_type(*spec_statement)) {
case parse_bool_and: { // this is not allowed
errored = append_syntax_error( errored = append_syntax_error(
&parse_errors, spec_statement->source_start, &parse_errors, spec_statement->source_start,
BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and"); BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and");
break; break;
case parse_bool_or: }
case parse_bool_or: { // this is not allowed
errored = append_syntax_error( errored = append_syntax_error(
&parse_errors, spec_statement->source_start, &parse_errors, spec_statement->source_start,
BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or"); BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or");
break; break;
case parse_bool_not:
// This one is OK.
break;
}
}
} }
// All others are OK.
default: { break; }
} }
break; break;
} }