lint: constant conditional operator

This commit is contained in:
Kurtis Rader 2016-11-01 21:19:34 -07:00
parent 71e69b6d75
commit f6047f02d6
12 changed files with 31 additions and 44 deletions

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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!

View file

@ -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"<no file>");
@ -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();
}
}

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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,

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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,