connection, transport: Assert that timeout >= -1 where it matters

We recommend that assertions are disabled in production builds of dbus,
which means that they are "cheap" to add to development builds as
"executable documentation" for our assumptions.

Lower-level code assumes that timeouts must be either -1 to block
forever, or non-negative to block for a finite time (but possibly 0,
to poll without blocking).

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2025-05-16 12:02:52 +01:00
parent e3dcdc6227
commit 481c3cd168
2 changed files with 10 additions and 1 deletions

View file

@ -1205,7 +1205,10 @@ _dbus_connection_do_iteration_unlocked (DBusConnection *connection,
int timeout_milliseconds)
{
_dbus_verbose ("start\n");
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
HAVE_LOCK_CHECK (connection);
if (connection->n_outgoing == 0)
@ -3694,6 +3697,9 @@ _dbus_connection_read_write_dispatch (DBusConnection *connection,
DBusDispatchStatus dstatus;
dbus_bool_t progress_possible;
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
/* Need to grab a ref here in case we're a private connection and
* the user drops the last ref in a handler we call; see bug
* https://bugs.freedesktop.org/show_bug.cgi?id=15635

View file

@ -1003,6 +1003,9 @@ _dbus_transport_do_iteration (DBusTransport *transport,
unsigned int flags,
int timeout_milliseconds)
{
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
_dbus_assert (transport->vtable->do_iteration != NULL);
_dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",