From: Simon McVittie Date: Fri, 16 May 2025 11:02:52 +0000 (+0100) Subject: connection, transport: Assert that timeout >= -1 where it matters X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=481c3cd16881097bd0077fa8f04924b39057a044;p=thirdparty%2Fdbus.git 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 --- diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 8c564deb4..0694fe7f7 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -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 diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index dd31a82b7..32f47a874 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -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",