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; break;
} }
default: { default: {
assert(0 && "Unexpected character in builtin_echo argument"); DIE("unexpected character in builtin_echo argument");
break; abort();
} }
} }
} }
@ -2853,7 +2853,7 @@ static const wcstring hist_cmd_to_string(hist_cmd_t hist_cmd) {
case HIST_SAVE: case HIST_SAVE:
return L"save"; return L"save";
default: default:
assert(0 && "Unhandled hist_cmd_t constant!"); DIE("unhandled hist_cmd_t constant");
abort(); abort();
} }
} }

View file

@ -518,8 +518,8 @@ expression *test_parser::parse_expression(unsigned int start, unsigned int end)
unsigned int argc = end - start; unsigned int argc = end - start;
switch (argc) { switch (argc) {
case 0: { case 0: {
assert(0); // should have been caught by the above test DIE("argc should not be zero"); // should have been caught by the above test
return NULL; abort();
} }
case 1: { case 1: {
return error(L"Missing argument at index %u", start + 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: case option_type_double_long:
return 2; return 2;
} }
assert(0 && "Unreachable"); DIE("unreachable");
} }
} complete_entry_opt_t; } complete_entry_opt_t;

View file

@ -284,7 +284,7 @@ static void universal_callback(fish_message_type_t type, const wchar_t *name) {
break; break;
} }
default: { default: {
assert(0 && "Unhandled fish_message_type_t constant!"); DIE("unhandled fish_message_type_t constant");
abort(); abort();
} }
} }

View file

@ -1071,7 +1071,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
void post_notification() { void post_notification() {
if (region != NULL) { if (region != NULL) {
/* Read off the seed */ /* 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. // Increment it. Don't let it wrap to zero.
do { do {
@ -1080,9 +1080,9 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
last_seed = seed; last_seed = seed;
// Write out our data. // Write out our data.
region->magic = htonl(SHMEM_MAGIC_NUMBER); region->magic = htonl(SHMEM_MAGIC_NUMBER); //!OCLINT(constant cond op)
region->version = htonl(SHMEM_VERSION_CURRENT); region->version = htonl(SHMEM_VERSION_CURRENT); //!OCLINT(constant cond op)
region->universal_variable_seed = htonl(seed); 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 poll() {
bool result = false; bool result = false;
if (region != NULL) { 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) { if (seed != last_seed) {
result = true; result = true;
last_seed = seed; last_seed = seed;
@ -1313,7 +1313,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t {
if (pipe_fd >= 0) { if (pipe_fd >= 0) {
// We need to write some data (any data) to the pipe, then wait for a while, then read // 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. // 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); ssize_t amt_written = write(this->pipe_fd, &pid_nbo, sizeof pid_nbo);
if (amt_written < 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) { if (amt_written < 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) {
// Very unsual: the pipe is full! // 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; break;
} }
default: { default: {
// Unknown type, should never happen. DIE("unhandled io_mode constant");
assert(0 && "Unhandled io_mode constant");
abort(); abort();
} }
} }
@ -442,7 +441,7 @@ void exec_job(parser_t &parser, job_t *j) {
j->first_process->completed = 1; j->first_process->completed = 1;
return; 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 // 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: case INTERNAL_EXEC:
// We should have handled exec up above. // We should have handled exec up above.
assert( DIE("INTERNAL_EXEC process found in pipeline, where it should never be. Aborting.");
0 && abort();
"INTERNAL_EXEC process found in pipeline, where it should never be. Aborting.");
break;
} }
if (exec_error) { 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); setup_child_process(j, p, process_net_io_chain);
safe_launch_process(p, actual_cmd, argv, envv); safe_launch_process(p, actual_cmd, argv, envv);
// safe_launch_process _never_ returns... // safe_launch_process _never_ returns...
assert(0 && "safe_launch_process should not have returned"); DIE("safe_launch_process should not have returned");
} else { } else {
debug(2, L"Fork #%d, pid %d: external command '%s' from '%ls'\n", debug(2, L"Fork #%d, pid %d: external command '%s' from '%ls'\n",
g_fork_count, pid, p->argv0(), file ? file : L"<no file>"); 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 // This is the parent process. Store away information on the child, and possibly
// fice it control over the terminal. // fice it control over the terminal.
p->pid = pid; p->pid = pid;
set_child_group(j, p, 0); set_child_group(j, p, 0);
break; break;
} }
case INTERNAL_EXEC: { case INTERNAL_EXEC: {
// We should have handled exec up above. // We should have handled exec up above.
assert( DIE("INTERNAL_EXEC process found in pipeline, where it should never be. Aborting.");
0 && abort();
"INTERNAL_EXEC process found in pipeline, where it should never be. Aborting.");
break;
} }
} }

View file

@ -424,11 +424,6 @@ int main(int argc, char **argv) {
int res = 1; int res = 1;
int my_optind = 0; 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"; program_name = L"fish";
set_main_thread(); set_main_thread();
setup_fork_guards(); setup_fork_guards();

View file

@ -615,7 +615,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
return false; return false;
} }
default: { default: {
assert(0 && "Unhandled selection_direction_t constant"); DIE("unhandled selection_direction_t constant");
abort(); 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; new_selected_completion_idx = selected_completion_idx - 1;
} }
} else { } else {
assert(0 && "Unknown non-cardinal direction"); DIE("unknown non-cardinal direction");
} }
} else { } else {
// Cardinal directions. We have a completion index; we wish to compute its row and column. // 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; break;
} }
default: { default: {
assert(0 && "Unknown cardinal direction"); DIE("unknown cardinal direction");
break; abort();
} }
} }

View file

@ -332,8 +332,8 @@ static inline parse_token_type_t parse_token_type_from_tokenizer_token(
default: { default: {
fprintf(stderr, "Bad token type %d passed to %s\n", (int)tokenizer_token_type, fprintf(stderr, "Bad token type %d passed to %s\n", (int)tokenizer_token_type,
__FUNCTION__); __FUNCTION__);
assert(0); DIE("bad token type");
break; abort();
} }
} }
return result; return result;
@ -1311,8 +1311,7 @@ const parse_node_t &parse_node_tree_t::find_child(const parse_node_t &parent,
return *child; return *child;
} }
} }
PARSE_ASSERT(0); DIE("failed to find child node");
return *(parse_node_t *)(NULL); // unreachable
} }
const parse_node_t *parse_node_tree_t::get_parent(const parse_node_t &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; break;
} }
default: { default: {
assert(0 && "Unhandled block_type_t constant"); DIE("unhandled block_type_t constant");
abort(); abort();
} }
} }

View file

@ -318,8 +318,8 @@ void tokenizer_t::read_string() {
break; break;
} }
default: { default: {
assert(0 && "Unexpected mode in read_string"); DIE("unexpected mode in read_string");
break; abort();
} }
} }
return; 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, bool wildcard_complete(const wcstring &str, const wchar_t *wc, const wchar_t *desc,