test, tools: assert impossible values of local enums are not reached
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 17 Jan 2017 20:41:17 +0000 (20:41 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 7 Apr 2017 11:07:01 +0000 (12:07 +0100)
Based on part of a patch from Thomas Zimmermann.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98191

dbus/dbus-marshal-recursive-util.c
dbus/dbus-sha.c
test/test-utils-glib.c
tools/dbus-cleanup-sockets.c
tools/dbus-launch.c
tools/dbus-monitor.c
tools/dbus-run-session.c

index d43972f..b30f588 100644 (file)
@@ -2390,6 +2390,9 @@ string_from_seed (char *buf,
    */
   switch (seed % 3)
     {
+    default:
+      /* don't alter it */
+      break;
     case 1:
       len += 2;
       break;
index 343b5d4..52c74f5 100644 (file)
@@ -693,7 +693,9 @@ get_next_expected_result (DBusString *results,
           i = 0;
           while (i < _dbus_string_get_length (result))
             {
-              switch (_dbus_string_get_byte (result, i))
+              unsigned char c = _dbus_string_get_byte (result, i);
+
+              switch (c)
                 {
                 case 'A':
                   _dbus_string_set_byte (result, i, 'a');
@@ -718,6 +720,9 @@ get_next_expected_result (DBusString *results,
                   _dbus_string_delete (result, i, 1);
                   --i; /* to offset ++i below */
                   break;
+                default:
+                  if ((c < '0' || c > '9') && (c < 'a' || c > 'f'))
+                    _dbus_assert_not_reached ("invalid SHA-1 test script");
                 }
 
               ++i;
index e13d20d..bb48195 100644 (file)
@@ -151,6 +151,8 @@ spawn_dbus_daemon (const gchar *binary,
 
             break;
 
+          case TEST_USER_ME:
+            /* cannot get here, fall through */
           default:
             g_assert_not_reached ();
         }
@@ -409,10 +411,15 @@ test_connect_to_bus_as_user (TestMainContext *ctx,
       case TEST_USER_ME:
         return test_connect_to_bus (ctx, address);
 
-      default:
+      case TEST_USER_ROOT:
+      case TEST_USER_MESSAGEBUS:
+      case TEST_USER_OTHER:
         g_test_skip ("setresuid() not available, or unsure about "
             "credentials-passing semantics on this platform");
         return NULL;
+
+      default:
+        g_return_val_if_reached (NULL);
     }
 
 #endif
index 1b6709a..994e57e 100644 (file)
@@ -328,6 +328,7 @@ handle_sockets (SocketEntry **entries,
           break;
 
         case SOCKET_UNLINKED:
+        default:
           fprintf (stderr, "Bad status from open_socket(), should not happen\n");
           exit (1);
           break;
index 65287af..75f39cf 100644 (file)
@@ -709,6 +709,8 @@ babysit (int   exit_with_session,
               strerror (errno));
       exit (1);
       break;
+    default:
+      _dbus_assert_not_reached ("Invalid read result");
     }
 
   verbose ("Got PID %ld from daemon\n",
@@ -1328,6 +1330,8 @@ main (int argc, char **argv)
                    strerror (errno));
           exit (1);
           break;
+        default:
+          _dbus_assert_not_reached ("Invalid read result");
         }
         
       close (bus_address_to_launcher_pipe[READ_END]);
@@ -1347,6 +1351,8 @@ main (int argc, char **argv)
                   strerror (errno));
          exit (1);
          break;
+       default:
+         _dbus_assert_not_reached ("Invalid read result");
        }
 
       end = NULL;
index aa28447..4edee29 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <config.h>
 
-#include "dbus/dbus-internals.h"        /* just for the macros */
+#include "dbus/dbus-internals.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -240,6 +240,10 @@ binary_filter_func (DBusConnection *connection,
           }
         break;
 
+      case BINARY_MODE_NOT:
+        _dbus_assert_not_reached ("wrong filter function");
+        break;
+
       case BINARY_MODE_RAW:
       default:
         /* nothing special, just the raw message stream */
@@ -474,8 +478,10 @@ main (int argc, char *argv[])
             case DBUS_BUS_SESSION:
               where = "session bus";
               break;
+            case DBUS_BUS_STARTER:
             default:
-              where = "";
+              /* We don't set type to anything else */
+              _dbus_assert_not_reached ("impossible bus type");
             }
         }
       fprintf (stderr, "Failed to open connection to %s: %s\n",
index 135f5d2..0adb5ad 100644 (file)
@@ -37,6 +37,7 @@
 #include <signal.h>
 
 #include "dbus/dbus.h"
+#include "dbus/dbus-internals.h"
 
 #define MAX_ADDR_LEN 512
 #define PIPE_READ_END  0
@@ -386,6 +387,9 @@ main (int argc, char **argv)
                me, strerror (errno));
       return 127;
       break;
+
+    default:
+      _dbus_assert_not_reached ("invalid read result");
     }
 
   close (bus_address_pipe[PIPE_READ_END]);