]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
connection, transport: Assert that timeout >= -1 where it matters
authorSimon McVittie <smcv@collabora.com>
Fri, 16 May 2025 11:02:52 +0000 (12:02 +0100)
committerSimon McVittie <smcv@collabora.com>
Fri, 23 May 2025 10:36:33 +0000 (10:36 +0000)
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>
dbus/dbus-connection.c
dbus/dbus-transport.c

index 8c564deb4dc72043ad64b19c9062284866fa9494..0694fe7f7acd770daedca77d878a0cf09260e958 100644 (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
index dd31a82b7b69964937b402ec6d9bfc9880adddd7..32f47a874dadef2451d37399ccb61fc236070842 100644 (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",