From c9ca9b9236f46518782ddba1e69d30a814e46c00 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 14 Apr 2015 23:17:40 +0200 Subject: [PATCH] Unify return value handling of BUS_CONNECTION_DATA(). This patch has been inspired by (and fixes) the following coverity scan issues: CID 54846: Dereference null return value (NULL_RETURNS). CID 54854: Dereference null return value (NULL_RETURNS). --- bus/connection.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 690f3a5..d2f5b22 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -35,6 +35,7 @@ #include #include #include +#include /* Trim executed commands to this length; we want to keep logs readable */ #define MAX_LOG_COMMAND_LEN 50 @@ -134,6 +135,7 @@ connection_get_loop (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); return bus_context_get_loop (d->connections->context); } @@ -638,6 +640,8 @@ static void check_pending_fds_cb (DBusConnection *connection) { BusConnectionData *d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + int n_pending_unix_fds_old = d->n_pending_unix_fds; int n_pending_unix_fds_new; @@ -1012,6 +1016,7 @@ bus_connection_get_loginfo (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); if (!bus_connection_is_active (connection)) return "inactive"; @@ -1248,8 +1253,9 @@ bus_connection_is_active (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); - return d != NULL && d->name != NULL; + return d->name != NULL; } dbus_bool_t @@ -2649,6 +2655,8 @@ bus_connection_get_peak_match_rules (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + return d->peak_match_rules; } @@ -2658,6 +2666,8 @@ bus_connection_get_peak_bus_names (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + return d->peak_bus_names; } #endif /* DBUS_ENABLE_STATS */ @@ -2668,8 +2678,9 @@ bus_connection_is_monitor (DBusConnection *connection) BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); - return d != NULL && d->link_in_monitors != NULL; + return d->link_in_monitors != NULL; } static dbus_bool_t -- 1.8.4.5