mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
lint: deal with "double negative" warnings
This commit is contained in:
parent
00303ed07f
commit
6e6b294a3f
14 changed files with 42 additions and 30 deletions
7
.oclint
7
.oclint
|
@ -51,3 +51,10 @@ disable-rules:
|
||||||
# and is therefore just noise. Disable this rule.
|
# and is therefore just noise. Disable this rule.
|
||||||
#
|
#
|
||||||
- InvertedLogic
|
- InvertedLogic
|
||||||
|
#
|
||||||
|
# The idea behind the "double negative" rule is sound since constructs
|
||||||
|
# like "!!(var & flag)" should be written as "static_cast<bool>(var &
|
||||||
|
# flag)". Unfortunately this rule has way too many false positives;
|
||||||
|
# especially in the context of assert statements. So disable this rule.
|
||||||
|
#
|
||||||
|
- DoubleNegative
|
||||||
|
|
|
@ -595,14 +595,14 @@ bool combining_expression::evaluate(wcstring_list_t &errors) {
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case test_combine_and:
|
case test_combine_and:
|
||||||
case test_combine_or: {
|
case test_combine_or: {
|
||||||
|
assert(!subjects.empty());
|
||||||
|
assert(combiners.size() + 1 == subjects.size());
|
||||||
|
|
||||||
// One-element case.
|
// One-element case.
|
||||||
if (subjects.size() == 1) return subjects.at(0)->evaluate(errors);
|
if (subjects.size() == 1) return subjects.at(0)->evaluate(errors);
|
||||||
|
|
||||||
// Evaluate our lists, remembering that AND has higher precedence than OR. We can
|
// Evaluate our lists, remembering that AND has higher precedence than OR. We can
|
||||||
// visualize this as a sequence of OR expressions of AND expressions.
|
// visualize this as a sequence of OR expressions of AND expressions.
|
||||||
assert(combiners.size() + 1 == subjects.size());
|
|
||||||
assert(!subjects.empty());
|
|
||||||
|
|
||||||
size_t idx = 0, max = subjects.size();
|
size_t idx = 0, max = subjects.size();
|
||||||
bool or_result = false;
|
bool or_result = false;
|
||||||
while (idx < max) {
|
while (idx < max) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ class rgb_color_t {
|
||||||
color24_t to_color24() const;
|
color24_t to_color24() const;
|
||||||
|
|
||||||
/// Returns whether the color is bold.
|
/// Returns whether the color is bold.
|
||||||
bool is_bold() const { return !!(flags & flag_bold); }
|
bool is_bold() const { return static_cast<bool>(flags & flag_bold); }
|
||||||
|
|
||||||
/// Set whether the color is bold.
|
/// Set whether the color is bold.
|
||||||
void set_bold(bool x) {
|
void set_bold(bool x) {
|
||||||
|
@ -107,7 +107,7 @@ class rgb_color_t {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the color is underlined.
|
/// Returns whether the color is underlined.
|
||||||
bool is_underline() const { return !!(flags & flag_underline); }
|
bool is_underline() const { return static_cast<bool>(flags & flag_underline); }
|
||||||
|
|
||||||
/// Set whether the color is underlined.
|
/// Set whether the color is underlined.
|
||||||
void set_underline(bool x) {
|
void set_underline(bool x) {
|
||||||
|
|
|
@ -768,9 +768,9 @@ static void escape_string_internal(const wchar_t *orig_in, size_t in_len, wcstri
|
||||||
assert(orig_in != NULL);
|
assert(orig_in != NULL);
|
||||||
|
|
||||||
const wchar_t *in = orig_in;
|
const wchar_t *in = orig_in;
|
||||||
bool escape_all = !!(flags & ESCAPE_ALL);
|
bool escape_all = static_cast<bool>(flags & ESCAPE_ALL);
|
||||||
bool no_quoted = !!(flags & ESCAPE_NO_QUOTED);
|
bool no_quoted = static_cast<bool>(flags & ESCAPE_NO_QUOTED);
|
||||||
bool no_tilde = !!(flags & ESCAPE_NO_TILDE);
|
bool no_tilde = static_cast<bool>(flags & ESCAPE_NO_TILDE);
|
||||||
|
|
||||||
int need_escape = 0;
|
int need_escape = 0;
|
||||||
int need_complex_escape = 0;
|
int need_complex_escape = 0;
|
||||||
|
@ -1117,8 +1117,8 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
wcstring result;
|
wcstring result;
|
||||||
result.reserve(input_len);
|
result.reserve(input_len);
|
||||||
|
|
||||||
const bool unescape_special = !!(flags & UNESCAPE_SPECIAL);
|
const bool unescape_special = static_cast<bool>(flags & UNESCAPE_SPECIAL);
|
||||||
const bool allow_incomplete = !!(flags & UNESCAPE_INCOMPLETE);
|
const bool allow_incomplete = static_cast<bool>(flags & UNESCAPE_INCOMPLETE);
|
||||||
|
|
||||||
int bracket_count = 0;
|
int bracket_count = 0;
|
||||||
|
|
||||||
|
|
|
@ -289,9 +289,11 @@ class completer_t {
|
||||||
return flags & COMPLETION_REQUEST_AUTOSUGGESTION ? COMPLETE_AUTOSUGGEST : COMPLETE_DEFAULT;
|
return flags & COMPLETION_REQUEST_AUTOSUGGESTION ? COMPLETE_AUTOSUGGEST : COMPLETE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wants_descriptions() const { return !!(flags & COMPLETION_REQUEST_DESCRIPTIONS); }
|
bool wants_descriptions() const {
|
||||||
|
return static_cast<bool>(flags & COMPLETION_REQUEST_DESCRIPTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
bool fuzzy() const { return !!(flags & COMPLETION_REQUEST_FUZZY_MATCH); }
|
bool fuzzy() const { return static_cast<bool>(flags & COMPLETION_REQUEST_FUZZY_MATCH); }
|
||||||
|
|
||||||
fuzzy_match_type_t max_fuzzy_match_type() const {
|
fuzzy_match_type_t max_fuzzy_match_type() const {
|
||||||
// If we are doing fuzzy matching, request all types; if not request only prefix matching.
|
// If we are doing fuzzy matching, request all types; if not request only prefix matching.
|
||||||
|
|
|
@ -1401,8 +1401,8 @@ static expand_error_t expand_stage_wildcards(const wcstring &input, std::vector<
|
||||||
// which may be CDPATH if the special flag is set.
|
// which may be CDPATH if the special flag is set.
|
||||||
const wcstring working_dir = env_get_pwd_slash();
|
const wcstring working_dir = env_get_pwd_slash();
|
||||||
wcstring_list_t effective_working_dirs;
|
wcstring_list_t effective_working_dirs;
|
||||||
bool for_cd = !!(flags & EXPAND_SPECIAL_FOR_CD);
|
bool for_cd = static_cast<bool>(flags & EXPAND_SPECIAL_FOR_CD);
|
||||||
bool for_command = !!(flags & EXPAND_SPECIAL_FOR_COMMAND);
|
bool for_command = static_cast<bool>(flags & EXPAND_SPECIAL_FOR_COMMAND);
|
||||||
if (!for_cd && !for_command) {
|
if (!for_cd && !for_command) {
|
||||||
// Common case.
|
// Common case.
|
||||||
effective_working_dirs.push_back(working_dir);
|
effective_working_dirs.push_back(working_dir);
|
||||||
|
|
|
@ -87,7 +87,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
|
||||||
path_flags_t flags) {
|
path_flags_t flags) {
|
||||||
ASSERT_IS_BACKGROUND_THREAD();
|
ASSERT_IS_BACKGROUND_THREAD();
|
||||||
|
|
||||||
const bool require_dir = !!(flags & PATH_REQUIRE_DIR);
|
const bool require_dir = static_cast<bool>(flags & PATH_REQUIRE_DIR);
|
||||||
wcstring clean_potential_path_fragment;
|
wcstring clean_potential_path_fragment;
|
||||||
int has_magic = 0;
|
int has_magic = 0;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
|
@ -115,7 +115,8 @@ static bool write_background_color(unsigned char idx) {
|
||||||
|
|
||||||
// Exported for builtin_set_color's usage only.
|
// Exported for builtin_set_color's usage only.
|
||||||
bool write_color(rgb_color_t color, bool is_fg) {
|
bool write_color(rgb_color_t color, bool is_fg) {
|
||||||
bool supports_term24bit = !!(output_get_color_support() & color_support_term24bit);
|
bool supports_term24bit =
|
||||||
|
static_cast<bool>(output_get_color_support() & color_support_term24bit);
|
||||||
if (!supports_term24bit || !color.is_rgb()) {
|
if (!supports_term24bit || !color.is_rgb()) {
|
||||||
// Indexed or non-24 bit color.
|
// Indexed or non-24 bit color.
|
||||||
unsigned char idx = index_for_color(color);
|
unsigned char idx = index_for_color(color);
|
||||||
|
@ -386,7 +387,7 @@ rgb_color_t best_color(const std::vector<rgb_color_t> &candidates, color_support
|
||||||
}
|
}
|
||||||
// If we have both RGB and named colors, then prefer rgb if term256 is supported.
|
// If we have both RGB and named colors, then prefer rgb if term256 is supported.
|
||||||
rgb_color_t result = rgb_color_t::none();
|
rgb_color_t result = rgb_color_t::none();
|
||||||
bool has_term256 = !!(support & color_support_term256);
|
bool has_term256 = static_cast<bool>(support & color_support_term256);
|
||||||
if ((!first_rgb.is_none() && has_term256) || first_named.is_none()) {
|
if ((!first_rgb.is_none() && has_term256) || first_named.is_none()) {
|
||||||
result = first_rgb;
|
result = first_rgb;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -118,7 +118,9 @@ class parse_node_t {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicate if the node has comment nodes.
|
/// Indicate if the node has comment nodes.
|
||||||
bool has_comments() const { return !!(this->flags & parse_node_flag_has_comments); }
|
bool has_comments() const {
|
||||||
|
return static_cast<bool>(this->flags & parse_node_flag_has_comments);
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets source for the node, or the empty string if it has no source.
|
/// Gets source for the node, or the empty string if it has no source.
|
||||||
wcstring get_source(const wcstring &str) const {
|
wcstring get_source(const wcstring &str) const {
|
||||||
|
|
|
@ -247,7 +247,7 @@ void job_set_flag(job_t *j, unsigned int flag, int set) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int job_get_flag(const job_t *j, unsigned int flag) { return !!(j->flags & flag); }
|
int job_get_flag(const job_t *j, unsigned int flag) { return static_cast<bool>(j->flags & flag); }
|
||||||
|
|
||||||
int job_signal(job_t *j, int signal) {
|
int job_signal(job_t *j, int signal) {
|
||||||
pid_t my_pid = getpid();
|
pid_t my_pid = getpid();
|
||||||
|
|
|
@ -1027,9 +1027,9 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
const wcstring &command_line, size_t *inout_cursor_pos,
|
const wcstring &command_line, size_t *inout_cursor_pos,
|
||||||
bool append_only) {
|
bool append_only) {
|
||||||
const wchar_t *val = val_str.c_str();
|
const wchar_t *val = val_str.c_str();
|
||||||
bool add_space = !(flags & COMPLETE_NO_SPACE);
|
bool add_space = !static_cast<bool>(flags & COMPLETE_NO_SPACE);
|
||||||
bool do_replace = !!(flags & COMPLETE_REPLACES_TOKEN);
|
bool do_replace = static_cast<bool>(flags & COMPLETE_REPLACES_TOKEN);
|
||||||
bool do_escape = !(flags & COMPLETE_DONT_ESCAPE);
|
bool do_escape = !static_cast<bool>(flags & COMPLETE_DONT_ESCAPE);
|
||||||
|
|
||||||
const size_t cursor_pos = *inout_cursor_pos;
|
const size_t cursor_pos = *inout_cursor_pos;
|
||||||
bool back_into_trailing_quote = false;
|
bool back_into_trailing_quote = false;
|
||||||
|
@ -1046,7 +1046,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
|
|
||||||
if (do_escape) {
|
if (do_escape) {
|
||||||
// Respect COMPLETE_DONT_ESCAPE_TILDES.
|
// Respect COMPLETE_DONT_ESCAPE_TILDES.
|
||||||
bool no_tilde = !!(flags & COMPLETE_DONT_ESCAPE_TILDES);
|
bool no_tilde = static_cast<bool>(flags & COMPLETE_DONT_ESCAPE_TILDES);
|
||||||
wcstring escaped =
|
wcstring escaped =
|
||||||
escape(val, ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0));
|
escape(val, ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0));
|
||||||
sb.append(escaped);
|
sb.append(escaped);
|
||||||
|
@ -1426,7 +1426,7 @@ static bool handle_completions(const std::vector<completion_t> &comp,
|
||||||
if (el.match.type > best_match_type) continue;
|
if (el.match.type > best_match_type) continue;
|
||||||
|
|
||||||
// Only use completions that match replace_token.
|
// Only use completions that match replace_token.
|
||||||
bool completion_replace_token = !!(el.flags & COMPLETE_REPLACES_TOKEN);
|
bool completion_replace_token = static_cast<bool>(el.flags & COMPLETE_REPLACES_TOKEN);
|
||||||
if (completion_replace_token != will_replace_token) continue;
|
if (completion_replace_token != will_replace_token) continue;
|
||||||
|
|
||||||
// Don't use completions that want to replace, if we cannot replace them.
|
// Don't use completions that want to replace, if we cannot replace them.
|
||||||
|
|
|
@ -64,10 +64,10 @@ tokenizer_t::tokenizer_t(const wchar_t *b, tok_flags_t flags)
|
||||||
continue_line_after_comment(false) {
|
continue_line_after_comment(false) {
|
||||||
assert(b != NULL);
|
assert(b != NULL);
|
||||||
|
|
||||||
this->accept_unfinished = !!(flags & TOK_ACCEPT_UNFINISHED);
|
this->accept_unfinished = static_cast<bool>(flags & TOK_ACCEPT_UNFINISHED);
|
||||||
this->show_comments = !!(flags & TOK_SHOW_COMMENTS);
|
this->show_comments = static_cast<bool>(flags & TOK_SHOW_COMMENTS);
|
||||||
this->squash_errors = !!(flags & TOK_SQUASH_ERRORS);
|
this->squash_errors = static_cast<bool>(flags & TOK_SQUASH_ERRORS);
|
||||||
this->show_blank_lines = !!(flags & TOK_SHOW_BLANK_LINES);
|
this->show_blank_lines = static_cast<bool>(flags & TOK_SHOW_BLANK_LINES);
|
||||||
|
|
||||||
this->has_next = (*b != L'\0');
|
this->has_next = (*b != L'\0');
|
||||||
this->tok_next();
|
this->tok_next();
|
||||||
|
|
|
@ -502,7 +502,7 @@ class wildcard_expander_t {
|
||||||
|
|
||||||
void add_expansion_result(const wcstring &result) {
|
void add_expansion_result(const wcstring &result) {
|
||||||
// This function is only for the non-completions case.
|
// This function is only for the non-completions case.
|
||||||
assert(!(this->flags & EXPAND_FOR_COMPLETIONS));
|
assert(!static_cast<bool>(this->flags & EXPAND_FOR_COMPLETIONS));
|
||||||
if (this->completion_set.insert(result).second) {
|
if (this->completion_set.insert(result).second) {
|
||||||
append_completion(this->resolved_completions, result);
|
append_completion(this->resolved_completions, result);
|
||||||
this->did_add = true;
|
this->did_add = true;
|
||||||
|
|
|
@ -79,7 +79,7 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou
|
||||||
if (stat(fullpath.c_str(), &buf) != 0) {
|
if (stat(fullpath.c_str(), &buf) != 0) {
|
||||||
is_dir = false;
|
is_dir = false;
|
||||||
} else {
|
} else {
|
||||||
is_dir = !!(S_ISDIR(buf.st_mode));
|
is_dir = static_cast<bool>(S_ISDIR(buf.st_mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*out_is_dir = is_dir;
|
*out_is_dir = is_dir;
|
||||||
|
|
Loading…
Reference in a new issue