test, tools: assert impossible values of local enums are not reached

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
This commit is contained in:
Simon McVittie 2017-01-17 20:41:17 +00:00 committed by Simon McVittie
parent ec6cf23718
commit 40560fa0c7
7 changed files with 36 additions and 4 deletions

View file

@ -2390,6 +2390,9 @@ string_from_seed (char *buf,
*/
switch (seed % 3)
{
default:
/* don't alter it */
break;
case 1:
len += 2;
break;

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

View 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

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

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

View 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",

View 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]);