From f6047f02d699275dcb94e6c15cc6611433bb0501 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Tue, 1 Nov 2016 21:19:34 -0700 Subject: [PATCH] lint: constant conditional operator --- src/builtin.cpp | 6 +++--- src/builtin_test.cpp | 4 ++-- src/complete.cpp | 2 +- src/env.cpp | 2 +- src/env_universal_common.cpp | 12 ++++++------ src/exec.cpp | 21 +++++++-------------- src/fish.cpp | 5 ----- src/pager.cpp | 8 ++++---- src/parse_tree.cpp | 7 +++---- src/parser.cpp | 2 +- src/tokenizer.cpp | 4 ++-- src/wildcard.cpp | 2 +- 12 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index e173d157f..61572fdb4 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -1360,8 +1360,8 @@ static int builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) break; } default: { - assert(0 && "Unexpected character in builtin_echo argument"); - break; + DIE("unexpected character in builtin_echo argument"); + abort(); } } } @@ -2853,7 +2853,7 @@ static const wcstring hist_cmd_to_string(hist_cmd_t hist_cmd) { case HIST_SAVE: return L"save"; default: - assert(0 && "Unhandled hist_cmd_t constant!"); + DIE("unhandled hist_cmd_t constant"); abort(); } } diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 942ddc2f7..b18e35707 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -518,8 +518,8 @@ expression *test_parser::parse_expression(unsigned int start, unsigned int end) unsigned int argc = end - start; switch (argc) { case 0: { - assert(0); // should have been caught by the above test - return NULL; + DIE("argc should not be zero"); // should have been caught by the above test + abort(); } case 1: { return error(L"Missing argument at index %u", start + 1); diff --git a/src/complete.cpp b/src/complete.cpp index 5d54463ec..f557146c1 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -119,7 +119,7 @@ typedef struct complete_entry_opt { case option_type_double_long: return 2; } - assert(0 && "Unreachable"); + DIE("unreachable"); } } complete_entry_opt_t; diff --git a/src/env.cpp b/src/env.cpp index 2ac7fe2ba..5c773bb70 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -284,7 +284,7 @@ static void universal_callback(fish_message_type_t type, const wchar_t *name) { break; } default: { - assert(0 && "Unhandled fish_message_type_t constant!"); + DIE("unhandled fish_message_type_t constant"); abort(); } } diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index 69d0a2d3e..d0fcdab3c 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -1071,7 +1071,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { void post_notification() { if (region != NULL) { /* Read off the seed */ - uint32_t seed = ntohl(region->universal_variable_seed); + uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op) // Increment it. Don't let it wrap to zero. do { @@ -1080,9 +1080,9 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { last_seed = seed; // Write out our data. - region->magic = htonl(SHMEM_MAGIC_NUMBER); - region->version = htonl(SHMEM_VERSION_CURRENT); - region->universal_variable_seed = htonl(seed); + region->magic = htonl(SHMEM_MAGIC_NUMBER); //!OCLINT(constant cond op) + region->version = htonl(SHMEM_VERSION_CURRENT); //!OCLINT(constant cond op) + region->universal_variable_seed = htonl(seed); //!OCLINT(constant cond op) } } @@ -1103,7 +1103,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { bool poll() { bool result = false; if (region != NULL) { - uint32_t seed = ntohl(region->universal_variable_seed); + uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op) if (seed != last_seed) { result = true; last_seed = seed; @@ -1313,7 +1313,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t { if (pipe_fd >= 0) { // We need to write some data (any data) to the pipe, then wait for a while, then read // it back. Nobody is expected to read it except us. - int pid_nbo = htonl(getpid()); + int pid_nbo = htonl(getpid()); //!OCLINT(constant cond op) ssize_t amt_written = write(this->pipe_fd, &pid_nbo, sizeof pid_nbo); if (amt_written < 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) { // Very unsual: the pipe is full! diff --git a/src/exec.cpp b/src/exec.cpp index 89f395faf..d28917dcc 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -283,8 +283,7 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain, break; } default: { - // Unknown type, should never happen. - assert(0 && "Unhandled io_mode constant"); + DIE("unhandled io_mode constant"); abort(); } } @@ -442,7 +441,7 @@ void exec_job(parser_t &parser, job_t *j) { j->first_process->completed = 1; return; } - assert(0 && "This should be unreachable"); + DIE("this should be unreachable"); } // We may have block IOs that conflict with fd redirections. For example, we may have a command @@ -827,10 +826,8 @@ void exec_job(parser_t &parser, job_t *j) { case INTERNAL_EXEC: // We should have handled exec up above. - assert( - 0 && - "INTERNAL_EXEC process found in pipeline, where it should never be. Aborting."); - break; + DIE("INTERNAL_EXEC process found in pipeline, where it should never be. Aborting."); + abort(); } if (exec_error) { @@ -1071,7 +1068,7 @@ void exec_job(parser_t &parser, job_t *j) { setup_child_process(j, p, process_net_io_chain); safe_launch_process(p, actual_cmd, argv, envv); // safe_launch_process _never_ returns... - assert(0 && "safe_launch_process should not have returned"); + DIE("safe_launch_process should not have returned"); } else { debug(2, L"Fork #%d, pid %d: external command '%s' from '%ls'\n", g_fork_count, pid, p->argv0(), file ? file : L""); @@ -1085,18 +1082,14 @@ void exec_job(parser_t &parser, job_t *j) { // This is the parent process. Store away information on the child, and possibly // fice it control over the terminal. p->pid = pid; - set_child_group(j, p, 0); - break; } case INTERNAL_EXEC: { // We should have handled exec up above. - assert( - 0 && - "INTERNAL_EXEC process found in pipeline, where it should never be. Aborting."); - break; + DIE("INTERNAL_EXEC process found in pipeline, where it should never be. Aborting."); + abort(); } } diff --git a/src/fish.cpp b/src/fish.cpp index 644e62a6f..5a135b396 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -424,11 +424,6 @@ int main(int argc, char **argv) { int res = 1; int my_optind = 0; - // We can't do this at compile time due to the use of enum symbols. - assert(EXPAND_SENTINAL >= EXPAND_RESERVED_BASE && EXPAND_SENTINAL <= EXPAND_RESERVED_END); - assert(ANY_SENTINAL >= WILDCARD_RESERVED_BASE && ANY_SENTINAL <= WILDCARD_RESERVED_END); - assert(R_SENTINAL >= INPUT_COMMON_BASE && R_SENTINAL <= INPUT_COMMON_END); - program_name = L"fish"; set_main_thread(); setup_fork_guards(); diff --git a/src/pager.cpp b/src/pager.cpp index 9bea536e2..6036e7ca9 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -615,7 +615,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio return false; } default: { - assert(0 && "Unhandled selection_direction_t constant"); + DIE("unhandled selection_direction_t constant"); abort(); } } @@ -639,7 +639,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio new_selected_completion_idx = selected_completion_idx - 1; } } else { - assert(0 && "Unknown non-cardinal direction"); + DIE("unknown non-cardinal direction"); } } else { // Cardinal directions. We have a completion index; we wish to compute its row and column. @@ -711,8 +711,8 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio break; } default: { - assert(0 && "Unknown cardinal direction"); - break; + DIE("unknown cardinal direction"); + abort(); } } diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 213eb9a75..2d11c1d61 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -332,8 +332,8 @@ static inline parse_token_type_t parse_token_type_from_tokenizer_token( default: { fprintf(stderr, "Bad token type %d passed to %s\n", (int)tokenizer_token_type, __FUNCTION__); - assert(0); - break; + DIE("bad token type"); + abort(); } } return result; @@ -1311,8 +1311,7 @@ const parse_node_t &parse_node_tree_t::find_child(const parse_node_t &parent, return *child; } } - PARSE_ASSERT(0); - return *(parse_node_t *)(NULL); // unreachable + DIE("failed to find child node"); } const parse_node_t *parse_node_tree_t::get_parent(const parse_node_t &node, diff --git a/src/parser.cpp b/src/parser.cpp index 9e71ae062..f3a9111dc 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -869,7 +869,7 @@ wcstring block_t::description() const { break; } default: { - assert(0 && "Unhandled block_type_t constant"); + DIE("unhandled block_type_t constant"); abort(); } } diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 61ea9e349..2f871645d 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -318,8 +318,8 @@ void tokenizer_t::read_string() { break; } default: { - assert(0 && "Unexpected mode in read_string"); - break; + DIE("unexpected mode in read_string"); + abort(); } } return; diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 11bd751b3..cd8cb226d 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -297,7 +297,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, } } - assert(0 && "Unreachable code reached"); + DIE("unreachable code reached"); } bool wildcard_complete(const wcstring &str, const wchar_t *wc, const wchar_t *desc,