From 6e4fa288b37d8d2b0a883c1c3bde6054ee87527c Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 23 Aug 2016 20:43:37 +0200 Subject: Fix warnings from compiler option '-Wswitch-default' Signed-off-by: Thomas Zimmermann --- bus/config-parser-common.c | 5 ++-- bus/config-parser.c | 7 +++++ bus/dispatch.c | 12 ++++++++ bus/driver.c | 6 ++++ bus/main.c | 3 ++ bus/policy.c | 8 ++++++ configure.ac | 1 - dbus/dbus-credentials.c | 3 +- dbus/dbus-marshal-recursive-util.c | 58 ++++++++++++-------------------------- dbus/dbus-memory.c | 3 +- dbus/dbus-sha.c | 2 ++ dbus/dbus-spawn.c | 7 +++++ dbus/dbus-sysdeps-util-win.c | 2 ++ dbus/dbus-sysdeps-win.c | 9 ++++++ dbus/dbus-sysdeps.c | 2 ++ dbus/dbus-transport.c | 2 ++ tools/dbus-cleanup-sockets.c | 3 ++ tools/dbus-launch.c | 8 ++++++ tools/dbus-monitor.c | 3 ++ tools/dbus-run-session.c | 3 ++ 20 files changed, 102 insertions(+), 45 deletions(-) diff --git a/bus/config-parser-common.c b/bus/config-parser-common.c index 5db6b28..a429096 100644 --- a/bus/config-parser-common.c +++ b/bus/config-parser-common.c @@ -187,10 +187,11 @@ bus_config_parser_element_type_to_name (ElementType type) return "allow_anonymous"; case ELEMENT_APPARMOR: return "apparmor"; + default: + _dbus_assert_not_reached ("bad element type"); + break; } - _dbus_assert_not_reached ("bad element type"); - return NULL; } diff --git a/bus/config-parser.c b/bus/config-parser.c index b776a2d..780e211 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -1676,6 +1676,9 @@ append_rule_from_element (BusConfigParser *parser, rule)) goto nomem; break; + + default: + break; } bus_policy_rule_unref (rule); @@ -2097,6 +2100,7 @@ bus_config_parser_end_element (BusConfigParser *parser, case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS: case ELEMENT_ALLOW_ANONYMOUS: case ELEMENT_APPARMOR: + default: break; } @@ -2653,6 +2657,9 @@ bus_config_parser_content (BusConfigParser *parser, e->d.limit.name); } break; + + default: + break; } _DBUS_ASSERT_ERROR_IS_CLEAR (error); diff --git a/bus/dispatch.c b/bus/dispatch.c index 021dfc4..ddce97c 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -2953,6 +2953,9 @@ check_existent_service_no_auto_start (BusContext *context, goto out; break; + + default: + break; } } @@ -3549,6 +3552,9 @@ check_existent_service_auto_start (BusContext *context, case GOT_SOMETHING_ELSE: _dbus_warn ("Unexpected message after auto activation"); goto out; + + default: + break; } } @@ -4242,6 +4248,9 @@ check_shell_service_success_auto_start (BusContext *context, case GOT_SOMETHING_ELSE: _dbus_warn ("Unexpected message after auto activation"); goto out; + + default: + break; } } @@ -4695,6 +4704,9 @@ check_list_services (BusContext *context, } break; + + default: + break; } } diff --git a/bus/driver.c b/bus/driver.c index a53af64..19835af 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1660,6 +1660,8 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, break; case BUS_DRIVER_FOUND_ERROR: goto failed; + default: + break; } if (uid == DBUS_UID_UNSET) @@ -1727,6 +1729,8 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, break; case BUS_DRIVER_FOUND_ERROR: goto failed; + default: + break; } if (pid == DBUS_PID_UNSET) @@ -1924,6 +1928,8 @@ bus_driver_handle_get_connection_credentials (DBusConnection *connection, break; case BUS_DRIVER_FOUND_ERROR: goto failed; + default: + break; } reply = _dbus_asv_new_method_return (message, &reply_iter, &array_iter); diff --git a/bus/main.c b/bus/main.c index a325cea..f7c2d0b 100644 --- a/bus/main.c +++ b/bus/main.c @@ -128,6 +128,9 @@ signal_handler (int sig) } } break; + + default: + break; } } #endif /* DBUS_UNIX */ diff --git a/bus/policy.c b/bus/policy.c index 082f385..22175ef 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -69,6 +69,8 @@ bus_policy_rule_new (BusPolicyRuleType type, break; case BUS_POLICY_RULE_OWN: break; + default: + break; } return rule; @@ -116,6 +118,8 @@ bus_policy_rule_unref (BusPolicyRule *rule) break; case BUS_POLICY_RULE_GROUP: break; + default: + break; } dbus_free (rule); @@ -261,6 +265,8 @@ add_list_to_client (DBusList **list, if (!bus_client_policy_append_rule (client, rule)) return FALSE; break; + default: + break; } } @@ -834,6 +840,8 @@ bus_client_policy_optimize (BusClientPolicy *policy) case BUS_POLICY_RULE_GROUP: _dbus_assert_not_reached ("invalid rule"); break; + default: + break; } if (remove_preceding) diff --git a/configure.ac b/configure.ac index 8c05157..772fdea 100644 --- a/configure.ac +++ b/configure.ac @@ -1365,7 +1365,6 @@ dnl code and remove these flags. DISABLE_WARNINGS="$DISABLE_WARNINGS -Wno-suggest-attribute=format -Wno-suggest-attribute=noreturn - -Wno-switch-default -Wno-switch-enum -Wno-type-limits -Wno-undef" diff --git a/dbus/dbus-credentials.c b/dbus/dbus-credentials.c index 151bb00..a47e51e 100644 --- a/dbus/dbus-credentials.c +++ b/dbus/dbus-credentials.c @@ -267,9 +267,10 @@ _dbus_credentials_include (DBusCredentials *credentials, return credentials->linux_security_label != NULL; case DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID: return credentials->adt_audit_data != NULL; + default: + _dbus_assert_not_reached ("Unknown credential enum value"); } - _dbus_assert_not_reached ("Unknown credential enum value"); return FALSE; } diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c index 1f57ed8..76e0bd4 100644 --- a/dbus/dbus-marshal-recursive-util.c +++ b/dbus/dbus-marshal-recursive-util.c @@ -2067,27 +2067,15 @@ int16_from_seed (int seed) * just use seed itself, but that would only ever touch one byte of * the int so would miss some kinds of bug. */ - dbus_int16_t v; + static const dbus_int16_t v_of_seed[5] = { + SAMPLE_INT16, + SAMPLE_INT16_ALTERNATE, + -1, + _DBUS_INT16_MAX, + 1 + }; - v = 42; /* just to quiet compiler afaik */ - switch (seed % 5) - { - case 0: - v = SAMPLE_INT16; - break; - case 1: - v = SAMPLE_INT16_ALTERNATE; - break; - case 2: - v = -1; - break; - case 3: - v = _DBUS_INT16_MAX; - break; - case 4: - v = 1; - break; - } + dbus_int16_t v = v_of_seed[seed % _DBUS_N_ELEMENTS(v_of_seed)]; if (seed > 1) v *= seed; /* wraps around eventually, which is fine */ @@ -2204,27 +2192,15 @@ int32_from_seed (int seed) * just use seed itself, but that would only ever touch one byte of * the int so would miss some kinds of bug. */ - dbus_int32_t v; + static const dbus_int32_t v_of_seed[5] = { + SAMPLE_INT32, + SAMPLE_INT32_ALTERNATE, + -1, + _DBUS_INT_MAX, + 1 + }; - v = 42; /* just to quiet compiler afaik */ - switch (seed % 5) - { - case 0: - v = SAMPLE_INT32; - break; - case 1: - v = SAMPLE_INT32_ALTERNATE; - break; - case 2: - v = -1; - break; - case 3: - v = _DBUS_INT_MAX; - break; - case 4: - v = 1; - break; - } + dbus_int32_t v = v_of_seed[seed % _DBUS_N_ELEMENTS(v_of_seed)]; if (seed > 1) v *= seed; /* wraps around eventually, which is fine */ @@ -2417,6 +2393,8 @@ string_from_seed (char *buf, case 2: len -= 2; break; + default: + break; } if (len < 0) len = 0; diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index bba9884..bae0c6f 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -334,8 +334,9 @@ source_string (BlockSource source) return "malloc0"; case SOURCE_REALLOC_NULL: return "realloc(NULL)"; + default: + _dbus_assert_not_reached ("Invalid malloc block source ID"); } - _dbus_assert_not_reached ("Invalid malloc block source ID"); return "invalid!"; } diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c index 343b5d4..eb3b9ec 100644 --- a/dbus/dbus-sha.c +++ b/dbus/dbus-sha.c @@ -718,6 +718,8 @@ get_next_expected_result (DBusString *results, _dbus_string_delete (result, i, 1); --i; /* to offset ++i below */ break; + default: + break; } ++i; diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index c6e4e37..4872162 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -426,6 +426,9 @@ read_data (DBusBabysitter *sitter, case READ_STATUS_OK: break; + + default: + break; } if (got == 1) @@ -450,6 +453,8 @@ read_data (DBusBabysitter *sitter, return r; case READ_STATUS_OK: break; + default: + break; } if (got == 1) @@ -510,6 +515,8 @@ read_data (DBusBabysitter *sitter, return r; case READ_STATUS_OK: break; + default: + break; } sitter->grandchild_pid = pid; diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index dacb8d2..b3ad625 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -1380,6 +1380,8 @@ _dbus_lm_strerror(int error_number) return "The password does not meet the requirements of the password filter DLLs."; #endif + default: + break; } msg = strerror (error_number); if (msg == NULL) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index df7b7d4..2a95c52 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -323,6 +323,9 @@ _dbus_win_error_from_last_error (void) case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: return DBUS_ERROR_FILE_NOT_FOUND; + + default: + break; } return DBUS_ERROR_FAILED; @@ -2687,6 +2690,8 @@ HANDLE _dbus_global_lock (const char *mutexname) case WAIT_FAILED: case WAIT_TIMEOUT: return 0; + default: + break; } return mutex; @@ -3524,6 +3529,9 @@ _dbus_strerror (int error_number) case WSASYSCALLFAILURE: return "System call failure"; + + default: + break; } msg = strerror (error_number); if (msg == NULL) @@ -3687,6 +3695,7 @@ _dbus_logv (DBusSystemLogSeverity severity, case DBUS_SYSTEM_LOG_WARNING: s = "warning"; break; case DBUS_SYSTEM_LOG_SECURITY: s = "security"; break; case DBUS_SYSTEM_LOG_FATAL: s = "fatal"; break; + default: break; } if (log_flags & DBUS_LOG_FLAGS_SYSTEM_LOG) diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index c58377b..98ee7a7 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -668,6 +668,8 @@ _dbus_error_from_errno (int error_number) case ENOENT: return DBUS_ERROR_FILE_NOT_FOUND; #endif + default: + break; } return DBUS_ERROR_FAILED; diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index e9a7340..e3656d1 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -410,6 +410,8 @@ _dbus_transport_open (DBusAddressEntry *entry, _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); goto out; break; + default: + break; } } diff --git a/tools/dbus-cleanup-sockets.c b/tools/dbus-cleanup-sockets.c index 1b6709a..ad47d41 100644 --- a/tools/dbus-cleanup-sockets.c +++ b/tools/dbus-cleanup-sockets.c @@ -331,6 +331,9 @@ handle_sockets (SocketEntry **entries, fprintf (stderr, "Bad status from open_socket(), should not happen\n"); exit (1); break; + + default: + break; } if (se->fd >= 0) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 4c872c3..28fb48b 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -467,6 +467,8 @@ signal_handler (int sig) case SIGTERM: got_sighup = TRUE; break; + default: + break; } } @@ -702,6 +704,8 @@ babysit (int exit_with_session, strerror (errno)); exit (1); break; + default: + break; } verbose ("Got PID %ld from daemon\n", @@ -1315,6 +1319,8 @@ main (int argc, char **argv) strerror (errno)); exit (1); break; + default: + break; } close (bus_address_to_launcher_pipe[READ_END]); @@ -1334,6 +1340,8 @@ main (int argc, char **argv) strerror (errno)); exit (1); break; + default: + break; } end = NULL; diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index 483d42e..2839a7f 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -581,6 +581,9 @@ main (int argc, char *argv[]) } } break; + + default: + break; } while (dbus_connection_read_write_dispatch(connection, -1)) diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c index 105ab3b..e7590ad 100644 --- a/tools/dbus-run-session.c +++ b/tools/dbus-run-session.c @@ -378,6 +378,9 @@ main (int argc, char **argv) me, strerror (errno)); return 127; break; + + default: + break; } close (bus_address_pipe[PIPE_READ_END]); -- 2.7.4