lint: missing default in switch statements

This commit is contained in:
Kurtis Rader 2016-10-29 17:25:48 -07:00
parent fb979922b3
commit b0b2182535
17 changed files with 220 additions and 57 deletions

View file

@ -452,7 +452,6 @@ static int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv)
while (1) {
int opt_index = 0;
int opt = w.wgetopt_long_only(argc, argv, L"aehkKfM:m:", long_options, &opt_index);
if (opt == -1) break;
switch (opt) {
@ -501,6 +500,10 @@ static int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv)
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -625,6 +628,10 @@ static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -665,6 +672,10 @@ static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv
block = parser.block_at_index(++block_idx);
}
}
default: {
DIE("unexpected scope");
break;
}
}
if (block) {
block->event_blocks.push_front(eb);
@ -713,6 +724,10 @@ static int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **ar
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -759,6 +774,10 @@ static int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv)
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -812,6 +831,10 @@ static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **ar
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -870,6 +893,10 @@ static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **ar
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -934,6 +961,7 @@ static wcstring functions_def(const wcstring &name) {
append_format(out, L" --on-event %ls", next->str_param1.c_str());
break;
}
default: { DIE("unexpected next->type"); }
}
}
@ -1048,6 +1076,10 @@ static int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -1193,9 +1225,11 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
case L'7': {
return 7;
}
default: { break; }
}
if (base == 16) switch (wc) {
if (base == 16) {
switch (wc) {
case L'8': {
return 8;
}
@ -1226,7 +1260,10 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
case L'F': {
return 15;
}
default: { break; }
}
}
return UINT_MAX;
}
@ -1642,6 +1679,10 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
res = 1;
break;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -1760,6 +1801,10 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -1915,6 +1960,10 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv)
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -2125,7 +2174,6 @@ static int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **arg
};
int mode = NORMAL;
int argc = builtin_count_args(argv);
int res = STATUS_BUILTIN_OK;
@ -2213,11 +2261,18 @@ static int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **arg
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
if (!res) {
switch (mode) {
case DONE: {
break;
}
case CURRENT_FILENAME: {
const wchar_t *fn = parser.current_filename();
@ -2270,6 +2325,7 @@ static int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **arg
streams.out.append(parser.stack_trace());
break;
}
default: { break; }
}
}
@ -2426,6 +2482,10 @@ static int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **a
should_output_index = true;
break;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -127,6 +127,10 @@ static void replace_part(const wchar_t *begin, const wchar_t *end, const wchar_t
out_pos += wcslen(insert);
break;
}
default: {
DIE("unexpected append_mode");
break;
}
}
out.append(end);
reader_set_buffer(out, out_pos);
@ -326,6 +330,10 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return 1;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -470,6 +478,10 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
parse_util_token_extent(get_buffer(), get_cursor_pos(), &begin, &end, 0, 0);
break;
}
default: {
DIE("unexpected buffer_part");
break;
}
}
int arg_count = argc - w.woptind;

View file

@ -283,6 +283,10 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
res = true;
break;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -101,6 +101,10 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_
}
break;
}
default: {
DIE("unexpected mode");
break;
}
}
}
@ -159,6 +163,10 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return 1;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -541,6 +541,12 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
}
break;
}
default: {
// TODO: Determine if this should call DIE()
// WTF
DIE("unexpected opt");
break;
}
}
}

View file

@ -123,6 +123,9 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope,
}
switch (env_set(key, val_str, scope | ENV_USER)) {
case ENV_OK: {
break;
}
case ENV_PERM: {
streams.err.append_format(_(L"%ls: Tried to change the read-only variable '%ls'\n"),
L"set", key);
@ -143,6 +146,10 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope,
retcode = 1;
break;
}
default: {
DIE("unexpected env_set() ret val");
break;
}
}
return retcode;

View file

@ -77,13 +77,13 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Parse options to obtain the requested operation and the modifiers.
w.woptind = 0;
while (1) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -110,6 +110,10 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
case '?': {
return STATUS_BUILTIN_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -100,12 +100,13 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
escape_flags_t flags = ESCAPE_ALL;
wgetopter_t w;
for (;;) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -117,6 +118,10 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -145,11 +150,13 @@ static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_
bool quiet = false;
wgetopter_t w;
for (;;) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -161,6 +168,10 @@ static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -202,12 +213,12 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
bool quiet = false;
wgetopter_t w;
for (;;) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -219,6 +230,10 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -499,12 +514,12 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
bool regex = false;
wgetopter_t w;
for (;;) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -536,6 +551,10 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -731,12 +750,12 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
bool regex = false;
wgetopter_t w;
for (;;) {
int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);
int opt = w.wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1) {
if (opt == -1) {
break;
}
switch (c) {
switch (opt) {
case 0: {
break;
}
@ -760,6 +779,10 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -876,6 +899,10 @@ static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -989,6 +1016,10 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}
@ -1078,6 +1109,10 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -262,6 +262,10 @@ int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return 1;
}
default: {
DIE("unexpected opt");
break;
}
}
}

View file

@ -1220,6 +1220,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
to_append_or_none = unescape_special ? INTERNAL_SEPARATOR : NOT_A_WCHAR;
break;
}
default: { break; }
}
} else if (mode == mode_single_quotes) {
if (c == L'\\') {
@ -1297,6 +1298,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
}
break;
}
default: { break; }
}
}

View file

@ -211,6 +211,9 @@ extern bool has_working_tty_timestamps;
}
/// Pause for input, then exit the program. If supported, print a backtrace first.
// The `return` will never be run but silences oclint warnings. Especially when this is called
// from within a `switch` block. As of the time I'm writing this oclint doesn't recognize the
// `__attribute__((noreturn))` on the exit_without_destructors() function.
#define FATAL_EXIT() \
{ \
char exit_read_buff; \

View file

@ -476,6 +476,25 @@ static env_node_t *env_get_node(const wcstring &key) {
return env;
}
/// Set the value of the environment variable whose name matches key to val.
///
/// Memory policy: All keys and values are copied, the parameters can and should be freed by the
/// caller afterwards
///
/// \param key The key
/// \param val The value
/// \param mode The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL,
/// ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current
/// mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed.
///
/// Returns:
///
/// * ENV_OK on success.
/// * ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that
/// the user tried to change a read-only variable.
/// * ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric
/// variables set from the local or universal scopes, or set as exported.
/// * ENV_INVALID, the variable value was invalid. This applies only to special variables.
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode) {
ASSERT_IS_MAIN_THREAD();
bool has_changed_old = has_changed_exported;
@ -512,7 +531,7 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
umask(mask);
// Do not actually create a umask variable, on env_get, it will be calculated
// dynamically.
return 0;
return ENV_OK;
}
}
@ -636,7 +655,7 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
// debug( 1, L"env_set: return from event firing" );
react_to_variable_change(key);
return 0;
return ENV_OK;
}
/// Attempt to remove/free the specified key/value pair from the specified map.

View file

@ -36,8 +36,8 @@ enum {
};
typedef uint32_t env_mode_flags_t;
/// Error code for trying to alter read-only variable.
enum { ENV_PERM = 1, ENV_SCOPE, ENV_INVALID };
/// Return values for `env_set()`.
enum { ENV_OK, ENV_PERM, ENV_SCOPE, ENV_INVALID };
/// A struct of configuration directories, determined in main() that fish will optionally pass to
/// env_init.
@ -51,26 +51,6 @@ struct config_paths_t {
/// Initialize environment variable data.
void env_init(const struct config_paths_t *paths = NULL);
/// Set the value of the environment variable whose name matches key to val.
///
/// Memory policy: All keys and values are copied, the parameters can and should be freed by the
/// caller afterwards
///
/// \param key The key
/// \param val The value
/// \param mode The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL,
/// ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current
/// mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed.
///
/// \returns 0 on success or an error code on failiure.
///
/// The current error codes are:
///
/// * ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that
/// the user tried to change a read-only variable.
/// * ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric
/// variables set from the local or universal scopes, or set as exported.
/// * ENV_INVALID, the variable value was invalid. This applies only to special variables.
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t mode);
class env_var_t : public wcstring {

View file

@ -88,6 +88,10 @@ static int event_match(const event_t &classv, const event_t &instance) {
case EVENT_GENERIC: {
return instance.str_param1 == classv.str_param1;
}
default: {
DIE("unexpected classv.type");
break;
}
}
// This should never be reached.

View file

@ -534,6 +534,10 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(
case EXPAND_OK: {
break;
}
default: {
DIE("unexpected expand_string() return value");
break;
}
}
if (result == parse_execution_success && switch_values_expanded.size() != 1) {
@ -945,6 +949,10 @@ parse_execution_result_t parse_execution_context_t::determine_arguments(
case EXPAND_OK: {
break;
}
default: {
DIE("unexpected expand_string() return value");
break;
}
}
// Now copy over any expanded arguments. Do it using swap() to avoid extra allocations; this

View file

@ -1004,6 +1004,10 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t
}
break;
}
default: {
DIE("unexpected parse_util_locate_cmdsubst() return value");
break;
}
}
}

View file

@ -20,6 +20,7 @@
#include <limits>
#include <string>
#include "common.h"
#include "utf8.h"
#define _NXT 0x80
@ -137,9 +138,8 @@ static int __utf8_forbitten(unsigned char octet) {
case 0xff: {
return -1;
}
default: { return 0; }
}
return 0;
}
/// This function translates UTF-8 string into UCS-2 or UCS-4 string (all symbols will be in local
@ -288,18 +288,17 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
if ((flags & UTF8_IGNORE_ERROR) == 0) return 0;
continue;
}
if (w_wide <= 0x0000007f)
if (w_wide <= 0x0000007f) {
n = 1;
else if (w_wide <= 0x000007ff)
} else if (w_wide <= 0x000007ff) {
n = 2;
else if (w_wide <= 0x0000ffff)
} else if (w_wide <= 0x0000ffff) {
n = 3;
else if (w_wide <= 0x001fffff)
} else if (w_wide <= 0x001fffff) {
n = 4;
else if (w_wide <= 0x03ffffff)
n = 5;
else
n = 6; /// if (w_wide <= 0x7fffffff)
} else {
DIE("invalid wide char");
}
total += n;
@ -340,10 +339,14 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
p[0] = _SEQ4 | ((oc[1] & 0x1f) >> 2);
break;
}
default: {
DIE("unexpected utff8 len");
break;
}
}
// NOTE: do not check here for forbitten UTF-8 characters. They cannot appear here because
// we do proper convertion.
// NOTE: do not check here for forbidden UTF-8 characters. They cannot appear here because
// we do proper conversion.
p += n;
}