Commit 31b38090 authored by Simon McVittie's avatar Simon McVittie

Replace some runtime assertions with compile-time assertions

This requires a little bit of code re-ordering, because
_DBUS_STATIC_ASSERT can appear anywhere that a variable declaration
would be valid, i.e. not after executable code.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767Reviewed-by: default avatarAlban Crequy <alban.crequy@collabora.co.uk>
parent 0e3d08d4
......@@ -189,9 +189,9 @@ dbus_error_init (DBusError *error)
{
DBusRealError *real;
_dbus_return_if_fail (error != NULL);
_DBUS_STATIC_ASSERT (sizeof (DBusError) == sizeof (DBusRealError));
_dbus_assert (sizeof (DBusError) == sizeof (DBusRealError));
_dbus_return_if_fail (error != NULL);
real = (DBusRealError *)error;
......
......@@ -519,7 +519,7 @@ _dbus_hash_iter_init (DBusHashTable *table,
{
DBusRealHashIter *real;
_dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
_DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
......@@ -544,7 +544,7 @@ _dbus_hash_iter_next (DBusHashIter *iter)
{
DBusRealHashIter *real;
_dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
_DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
......@@ -746,7 +746,7 @@ _dbus_hash_iter_lookup (DBusHashTable *table,
DBusHashEntry *entry;
DBusHashEntry **bucket;
_dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
_DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
......
......@@ -599,7 +599,7 @@ marshal_2_octets (DBusString *str,
dbus_bool_t retval;
int orig_len;
_dbus_assert (sizeof (value) == 2);
_DBUS_STATIC_ASSERT (sizeof (value) == 2);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
value = DBUS_UINT16_SWAP_LE_BE (value);
......@@ -628,7 +628,7 @@ marshal_4_octets (DBusString *str,
dbus_bool_t retval;
int orig_len;
_dbus_assert (sizeof (value) == 4);
_DBUS_STATIC_ASSERT (sizeof (value) == 4);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
value = DBUS_UINT32_SWAP_LE_BE (value);
......@@ -657,7 +657,7 @@ marshal_8_octets (DBusString *str,
dbus_bool_t retval;
int orig_len;
_dbus_assert (sizeof (value) == 8);
_DBUS_STATIC_ASSERT (sizeof (value) == 8);
swap_8_octets (&value, byte_order);
......
......@@ -2024,7 +2024,7 @@ _dbus_message_iter_init_common (DBusMessage *message,
DBusMessageRealIter *real,
int iter_type)
{
_dbus_assert (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
_DBUS_STATIC_ASSERT (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
/* Since the iterator will read or write who-knows-what from the
* message, we need to get in the right byte order
......
......@@ -428,7 +428,7 @@ _dbus_signature_test (void)
const char *sig;
dbus_bool_t boolres;
_dbus_assert (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
_DBUS_STATIC_ASSERT (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
sig = "";
_dbus_assert (dbus_signature_validate (sig, NULL));
......
......@@ -133,11 +133,11 @@ _dbus_string_init_preallocated (DBusString *str,
int allocate_size)
{
DBusRealString *real;
_DBUS_STATIC_ASSERT (sizeof (DBusString) == sizeof (DBusRealString));
_dbus_assert (str != NULL);
_dbus_assert (sizeof (DBusString) == sizeof (DBusRealString));
real = (DBusRealString*) str;
/* It's very important not to touch anything
......
......@@ -1660,18 +1660,18 @@ _dbus_read_credentials_socket (int client_fd,
} cmsg;
#endif
uid_read = DBUS_UID_UNSET;
pid_read = DBUS_PID_UNSET;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
/* The POSIX spec certainly doesn't promise this, but
* we need these assertions to fail as soon as we're wrong about
* it so we can do the porting fixups
*/
_dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
_dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
_dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
_DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
_DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
_DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
uid_read = DBUS_UID_UNSET;
pid_read = DBUS_PID_UNSET;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_credentials_clear (credentials);
......@@ -2352,9 +2352,9 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
* we need these assertions to fail as soon as we're wrong about
* it so we can do the porting fixups
*/
_dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
_dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
_dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
_DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
_DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
_DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
if (!_dbus_credentials_add_pid(credentials, _dbus_getpid()))
return FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment