Merge branch 'scan-build' into 'main'

Fix various bugs found by scan-build and refresh scan-build config in CI

See merge request GNOME/glib!4005
This commit is contained in:
Michael Catanzaro 2024-04-15 15:47:45 +00:00
commit 5c8fbc3cda
12 changed files with 204 additions and 150 deletions

View File

@ -725,6 +725,22 @@ scan-build:
image: $FEDORA_IMAGE image: $FEDORA_IMAGE
stage: analysis stage: analysis
needs: [] needs: []
variables:
# FIXME: Eventually we want static analysis on the tests and copylibs, for
# code quality, but for the moment its just busywork.
# FIXME: Disable the dead code checkers for now because they create a lot of
# noise and dont indicate high severity problems.
SCAN_BUILD_FLAGS: >-
--exclude gio/tests/
--exclude girepository/tests/
--exclude glib/tests/
--exclude gmodule/tests/
--exclude gobject/tests/
--exclude gthread/tests/
--exclude girepository/cmph/
--exclude glib/libcharset/
--exclude gio/xdgmime/
-disable-checker deadcode.DeadStores
script: script:
- meson setup ${MESON_COMMON_OPTIONS} - meson setup ${MESON_COMMON_OPTIONS}
--werror --werror
@ -732,12 +748,13 @@ scan-build:
--prefix=$HOME/glib-installed --prefix=$HOME/glib-installed
--localstatedir=/var --localstatedir=/var
--libdir=lib --libdir=lib
-Dglib_debug=enabled
-Dsystemtap=true -Dsystemtap=true
-Ddtrace=true -Ddtrace=true
-Dinstalled_tests=true -Dinstalled_tests=true
-Dintrospection=enabled -Dintrospection=enabled
_scan_build _scan_build
- ninja -C _scan_build scan-build - SCANBUILD="$(pwd)/.gitlab-ci/scan-build.sh" ninja -C _scan_build scan-build
artifacts: artifacts:
name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}" name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}"
when: always when: always

15
.gitlab-ci/scan-build.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
#
# Copyright 2024 GNOME Foundation, Inc.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Original author: Philip Withnall
set -eu
# This script just exists so that we can set the scan-build flags in
# .gitlab-ci.yml and pass them into Mesons `scan-build` target.
# shellcheck disable=SC2086
exec scan-build ${SCAN_BUILD_FLAGS:-} "$@"

View File

@ -1897,6 +1897,7 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connect
if (out_serial == NULL) if (out_serial == NULL)
out_serial = &serial; out_serial = &serial;
*out_serial = 0;
if (timeout_msec == -1) if (timeout_msec == -1)
timeout_msec = 25 * 1000; timeout_msec = 25 * 1000;
@ -5363,6 +5364,9 @@ g_dbus_connection_register_object (GDBusConnection *connection,
out: out:
CONNECTION_UNLOCK (connection); CONNECTION_UNLOCK (connection);
if (ret == 0 && user_data_free_func != NULL)
user_data_free_func (user_data);
return ret; return ret;
} }
@ -7019,6 +7023,9 @@ g_dbus_connection_register_subtree (GDBusConnection *connection,
out: out:
CONNECTION_UNLOCK (connection); CONNECTION_UNLOCK (connection);
if (ret == 0 && user_data_free_func != NULL)
user_data_free_func (user_data);
return ret; return ret;
} }

View File

@ -1029,14 +1029,16 @@ g_resources_register_unlocked (GResource *resource)
static void static void
g_resources_unregister_unlocked (GResource *resource) g_resources_unregister_unlocked (GResource *resource)
{ {
if (g_list_find (registered_resources, resource) == NULL) GList *resource_link = g_list_find (registered_resources, resource);
if (resource_link == NULL)
{ {
g_warning ("Tried to remove not registered resource"); g_warning ("Tried to remove not registered resource");
} }
else else
{ {
registered_resources = g_list_remove (registered_resources, resource); g_resource_unref (resource_link->data);
g_resource_unref (resource); registered_resources = g_list_delete_link (registered_resources, resource_link);
} }
} }

View File

@ -336,7 +336,7 @@ introspect_callback (GDBusProxy *proxy,
res, res,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (result != NULL); g_assert_nonnull (result);
g_variant_get (result, "(s)", xml_data); g_variant_get (result, "(s)", xml_data);
g_variant_unref (result); g_variant_unref (result);
@ -381,7 +381,7 @@ get_nodes_at (GDBusConnection *c,
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (proxy != NULL); g_assert_nonnull (proxy);
/* do this async to avoid libdbus-1 deadlocks */ /* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL; xml_data = NULL;
@ -394,11 +394,11 @@ get_nodes_at (GDBusConnection *c,
(GAsyncReadyCallback) introspect_callback, (GAsyncReadyCallback) introspect_callback,
&xml_data); &xml_data);
g_main_loop_run (loop); g_main_loop_run (loop);
g_assert (xml_data != NULL); g_assert_nonnull (xml_data);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (node_info != NULL); g_assert_nonnull (node_info);
p = g_ptr_array_new (); p = g_ptr_array_new ();
for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++) for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++)
@ -440,7 +440,7 @@ has_interface (GDBusConnection *c,
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (proxy != NULL); g_assert_nonnull (proxy);
/* do this async to avoid libdbus-1 deadlocks */ /* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL; xml_data = NULL;
@ -453,11 +453,11 @@ has_interface (GDBusConnection *c,
(GAsyncReadyCallback) introspect_callback, (GAsyncReadyCallback) introspect_callback,
&xml_data); &xml_data);
g_main_loop_run (loop); g_main_loop_run (loop);
g_assert (xml_data != NULL); g_assert_nonnull (xml_data);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (node_info != NULL); g_assert_nonnull (node_info);
ret = (g_dbus_node_info_lookup_interface (node_info, interface_name) != NULL); ret = (g_dbus_node_info_lookup_interface (node_info, interface_name) != NULL);
@ -489,7 +489,7 @@ count_interfaces (GDBusConnection *c,
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (proxy != NULL); g_assert_nonnull (proxy);
/* do this async to avoid libdbus-1 deadlocks */ /* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL; xml_data = NULL;
@ -502,11 +502,11 @@ count_interfaces (GDBusConnection *c,
(GAsyncReadyCallback) introspect_callback, (GAsyncReadyCallback) introspect_callback,
&xml_data); &xml_data);
g_main_loop_run (loop); g_main_loop_run (loop);
g_assert (xml_data != NULL); g_assert_nonnull (xml_data);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (node_info != NULL); g_assert_nonnull (node_info);
ret = 0; ret = 0;
while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL) while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL)
@ -532,7 +532,7 @@ dyna_create_callback (GDBusProxy *proxy,
res, res,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (result != NULL); g_assert_nonnull (result);
g_variant_unref (result); g_variant_unref (result);
g_main_loop_quit (loop); g_main_loop_quit (loop);
@ -560,7 +560,7 @@ dyna_create (GDBusConnection *c,
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (proxy != NULL); g_assert_nonnull (proxy);
/* do this async to avoid libdbus-1 deadlocks */ /* do this async to avoid libdbus-1 deadlocks */
g_dbus_proxy_call (proxy, g_dbus_proxy_call (proxy,
@ -773,7 +773,7 @@ test_dispatch_thread_func (gpointer user_data)
"org.example.Foo", "org.example.Foo",
NULL, NULL,
&error); &error);
g_assert (foo_proxy != NULL); g_assert_nonnull (foo_proxy);
/* generic interfaces */ /* generic interfaces */
error = NULL; error = NULL;
@ -785,7 +785,7 @@ test_dispatch_thread_func (gpointer user_data)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (value != NULL); g_assert_nonnull (value);
g_variant_unref (value); g_variant_unref (value);
/* user methods */ /* user methods */
@ -798,8 +798,8 @@ test_dispatch_thread_func (gpointer user_data)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (value != NULL); g_assert_nonnull (value);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)"))); g_assert_true (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)")));
g_variant_get (value, "(&s)", &value_str); g_variant_get (value, "(&s)", &value_str);
g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!"); g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!");
g_variant_unref (value); g_variant_unref (value);
@ -815,7 +815,7 @@ test_dispatch_thread_func (gpointer user_data)
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.example.SomeError: How do you like them apples, buddy!"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.example.SomeError: How do you like them apples, buddy!");
g_error_free (error); g_error_free (error);
g_assert (value == NULL); g_assert_null (value);
error = NULL; error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy, value = g_dbus_proxy_call_sync (foo_proxy,
@ -828,7 +828,7 @@ test_dispatch_thread_func (gpointer user_data)
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Type of message, “(s)”, does not match expected type “()”"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Type of message, “(s)”, does not match expected type “()”");
g_error_free (error); g_error_free (error);
g_assert (value == NULL); g_assert_null (value);
error = NULL; error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy, value = g_dbus_proxy_call_sync (foo_proxy,
@ -841,7 +841,7 @@ test_dispatch_thread_func (gpointer user_data)
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method “NonExistantMethod”"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method “NonExistantMethod”");
g_error_free (error); g_error_free (error);
g_assert (value == NULL); g_assert_null (value);
error = NULL; error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy, value = g_dbus_proxy_call_sync (foo_proxy,
@ -853,7 +853,7 @@ test_dispatch_thread_func (gpointer user_data)
&error); &error);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
g_error_free (error); g_error_free (error);
g_assert (value == NULL); g_assert_null (value);
/* user properties */ /* user properties */
error = NULL; error = NULL;
@ -867,10 +867,10 @@ test_dispatch_thread_func (gpointer user_data)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (value != NULL); g_assert_nonnull (value);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)"))); g_assert_true (g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)")));
g_variant_get (value, "(v)", &inner); g_variant_get (value, "(v)", &inner);
g_assert (g_variant_is_of_type (inner, G_VARIANT_TYPE_STRING)); g_assert_true (g_variant_is_of_type (inner, G_VARIANT_TYPE_STRING));
g_assert_cmpstr (g_variant_get_string (inner, NULL), ==, "Property 'PropertyUno' Is What It Is!"); g_assert_cmpstr (g_variant_get_string (inner, NULL), ==, "Property 'PropertyUno' Is What It Is!");
g_variant_unref (value); g_variant_unref (value);
g_variant_unref (inner); g_variant_unref (inner);
@ -885,7 +885,7 @@ test_dispatch_thread_func (gpointer user_data)
-1, -1,
NULL, NULL,
&error); &error);
g_assert (value == NULL); g_assert_null (value);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such property “ThisDoesntExist”"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such property “ThisDoesntExist”");
g_error_free (error); g_error_free (error);
@ -900,7 +900,7 @@ test_dispatch_thread_func (gpointer user_data)
-1, -1,
NULL, NULL,
&error); &error);
g_assert (value == NULL); g_assert_null (value);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotReadable” is not readable"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotReadable” is not readable");
g_error_free (error); g_error_free (error);
@ -916,14 +916,14 @@ test_dispatch_thread_func (gpointer user_data)
-1, -1,
NULL, NULL,
&error); &error);
g_assert (value == NULL); g_assert_null (value);
if (args->check_remote_errors) if (args->check_remote_errors)
{ {
/* _with_closures variant doesn't support customizing error data. */ /* _with_closures variant doesn't support customizing error data. */
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FILE_INVALID); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FILE_INVALID);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.Spawn.FileInvalid: Returning some error instead of writing the value ''But Writable you are!'' to the property 'NotReadable'"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.Spawn.FileInvalid: Returning some error instead of writing the value ''But Writable you are!'' to the property 'NotReadable'");
} }
g_assert (error != NULL && error->domain == G_DBUS_ERROR); g_assert_true (error != NULL && error->domain == G_DBUS_ERROR);
g_error_free (error); g_error_free (error);
error = NULL; error = NULL;
@ -937,7 +937,7 @@ test_dispatch_thread_func (gpointer user_data)
-1, -1,
NULL, NULL,
&error); &error);
g_assert (value == NULL); g_assert_null (value);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotWritable” is not writable"); g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotWritable” is not writable");
g_error_free (error); g_error_free (error);
@ -952,8 +952,8 @@ test_dispatch_thread_func (gpointer user_data)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (value != NULL); g_assert_nonnull (value);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(a{sv})"))); g_assert_true (g_variant_is_of_type (value, G_VARIANT_TYPE ("(a{sv})")));
s = g_variant_print (value, TRUE); s = g_variant_print (value, TRUE);
g_assert_cmpstr (s, ==, "({'PropertyUno': <\"Property 'PropertyUno' Is What It Is!\">, 'NotWritable': <\"Property 'NotWritable' Is What It Is!\">},)"); g_assert_cmpstr (s, ==, "({'PropertyUno': <\"Property 'PropertyUno' Is What It Is!\">, 'NotWritable': <\"Property 'NotWritable' Is What It Is!\">},)");
g_free (s); g_free (s);
@ -1003,17 +1003,19 @@ test_object_registration (void)
guint non_subtree_object_path_bar_reg_id; guint non_subtree_object_path_bar_reg_id;
guint dyna_subtree_registration_id; guint dyna_subtree_registration_id;
guint num_successful_registrations; guint num_successful_registrations;
guint num_failed_registrations;
data.num_unregistered_calls = 0; data.num_unregistered_calls = 0;
data.num_unregistered_subtree_calls = 0; data.num_unregistered_subtree_calls = 0;
data.num_subtree_nodes = 0; data.num_subtree_nodes = 0;
num_successful_registrations = 0; num_successful_registrations = 0;
num_failed_registrations = 0;
error = NULL; error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (c != NULL); g_assert_nonnull (c);
registration_id = g_dbus_connection_register_object (c, registration_id = g_dbus_connection_register_object (c,
"/foo/boss", "/foo/boss",
@ -1023,7 +1025,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
boss_foo_reg_id = registration_id; boss_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1035,7 +1037,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
boss_bar_reg_id = registration_id; boss_bar_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1047,7 +1049,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
worker1_foo_reg_id = registration_id; worker1_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1059,7 +1061,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
worker1p1_foo_reg_id = registration_id; worker1p1_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1071,7 +1073,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
worker2_bar_reg_id = registration_id; worker2_bar_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1083,7 +1085,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
intern1_foo_reg_id = registration_id; intern1_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1096,11 +1098,12 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
intern2_bar_reg_id = registration_id; intern2_bar_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
/* register at the same path/interface - this should fail */ /* register at the same path/interface - this should fail and result in an
* immediate unregistration (so the user_data isnt leaked) */
registration_id = g_dbus_connection_register_object (c, registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern2", "/foo/boss/interns/intern2",
(GDBusInterfaceInfo *) &bar_interface_info, (GDBusInterfaceInfo *) &bar_interface_info,
@ -1109,10 +1112,12 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
g_assert (!g_dbus_error_is_remote_error (error)); g_assert_false (g_dbus_error_is_remote_error (error));
g_error_free (error); g_error_free (error);
error = NULL; error = NULL;
g_assert (registration_id == 0); g_assert_cmpuint (registration_id, ==, 0);
g_assert_cmpint (data.num_unregistered_calls, ==, 1);
num_failed_registrations++;
/* register at different interface - shouldn't fail */ /* register at different interface - shouldn't fail */
registration_id = g_dbus_connection_register_object (c, registration_id = g_dbus_connection_register_object (c,
@ -1123,14 +1128,14 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
intern2_foo_reg_id = registration_id; intern2_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
/* unregister it via the id */ /* unregister it via the id */
g_assert (g_dbus_connection_unregister_object (c, registration_id)); g_assert_true (g_dbus_connection_unregister_object (c, registration_id));
g_main_context_iteration (NULL, FALSE); g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_calls, ==, 1); g_assert_cmpint (data.num_unregistered_calls, ==, 2);
intern2_foo_reg_id = 0; intern2_foo_reg_id = 0;
/* register it back */ /* register it back */
@ -1142,7 +1147,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
intern2_foo_reg_id = registration_id; intern2_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1154,7 +1159,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
intern3_bar_reg_id = registration_id; intern3_bar_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1167,7 +1172,7 @@ test_object_registration (void)
on_subtree_unregistered, on_subtree_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (subtree_registration_id > 0); g_assert_cmpuint (subtree_registration_id, >, 0);
/* try registering it again.. this should fail */ /* try registering it again.. this should fail */
registration_id = g_dbus_connection_register_subtree (c, registration_id = g_dbus_connection_register_subtree (c,
"/foo/boss/executives", "/foo/boss/executives",
@ -1177,16 +1182,16 @@ test_object_registration (void)
on_subtree_unregistered, on_subtree_unregistered,
&error); &error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
g_assert (!g_dbus_error_is_remote_error (error)); g_assert_false (g_dbus_error_is_remote_error (error));
g_error_free (error); g_error_free (error);
error = NULL; error = NULL;
g_assert (registration_id == 0); g_assert_cmpuint (registration_id, ==, 0);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
/* unregister it, then register it again */ /* unregister it, then register it again */
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 0); g_assert_true (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_main_context_iteration (NULL, FALSE); g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1); g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2);
subtree_registration_id = g_dbus_connection_register_subtree (c, subtree_registration_id = g_dbus_connection_register_subtree (c,
"/foo/boss/executives", "/foo/boss/executives",
&subtree_vtable, &subtree_vtable,
@ -1195,7 +1200,7 @@ test_object_registration (void)
on_subtree_unregistered, on_subtree_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (subtree_registration_id > 0); g_assert_cmpuint (subtree_registration_id, >, 0);
/* try to register something under /foo/boss/executives - this should work /* try to register something under /foo/boss/executives - this should work
* because registered subtrees and registered objects can coexist. * because registered subtrees and registered objects can coexist.
@ -1211,7 +1216,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
non_subtree_object_path_bar_reg_id = registration_id; non_subtree_object_path_bar_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c, registration_id = g_dbus_connection_register_object (c,
@ -1222,7 +1227,7 @@ test_object_registration (void)
on_object_unregistered, on_object_unregistered,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
non_subtree_object_path_foo_reg_id = registration_id; non_subtree_object_path_foo_reg_id = registration_id;
num_successful_registrations++; num_successful_registrations++;
@ -1236,11 +1241,11 @@ test_object_registration (void)
(GDestroyNotify)g_ptr_array_unref, (GDestroyNotify)g_ptr_array_unref,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (dyna_subtree_registration_id > 0); g_assert_cmpuint (dyna_subtree_registration_id, >, 0);
/* First assert that we have no nodes in the dynamic subtree */ /* First assert that we have no nodes in the dynamic subtree */
nodes = get_nodes_at (c, "/foo/dyna"); nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 0); g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes); g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/dyna"), ==, 4); g_assert_cmpint (count_interfaces (c, "/foo/dyna"), ==, 4);
@ -1251,7 +1256,7 @@ test_object_registration (void)
g_ptr_array_add (dyna_data, g_strdup ("cat")); g_ptr_array_add (dyna_data, g_strdup ("cat"));
g_ptr_array_add (dyna_data, g_strdup ("cheezburger")); g_ptr_array_add (dyna_data, g_strdup ("cheezburger"));
nodes = get_nodes_at (c, "/foo/dyna"); nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 3); g_assert_cmpint (g_strv_length (nodes), ==, 3);
g_assert_cmpstr (nodes[0], ==, "cat"); g_assert_cmpstr (nodes[0], ==, "cat");
g_assert_cmpstr (nodes[1], ==, "cheezburger"); g_assert_cmpstr (nodes[1], ==, "cheezburger");
@ -1264,7 +1269,7 @@ test_object_registration (void)
/* Call a non-existing object path and assert that it has been created */ /* Call a non-existing object path and assert that it has been created */
dyna_create (c, "dynamicallycreated"); dyna_create (c, "dynamicallycreated");
nodes = get_nodes_at (c, "/foo/dyna"); nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 4); g_assert_cmpint (g_strv_length (nodes), ==, 4);
g_assert_cmpstr (nodes[0], ==, "cat"); g_assert_cmpstr (nodes[0], ==, "cat");
g_assert_cmpstr (nodes[1], ==, "cheezburger"); g_assert_cmpstr (nodes[1], ==, "cheezburger");
@ -1277,14 +1282,14 @@ test_object_registration (void)
* perverse that we round-trip to the bus to introspect ourselves ;-) * perverse that we round-trip to the bus to introspect ourselves ;-)
*/ */
nodes = get_nodes_at (c, "/"); nodes = get_nodes_at (c, "/");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 1); g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_assert_cmpstr (nodes[0], ==, "foo"); g_assert_cmpstr (nodes[0], ==, "foo");
g_strfreev (nodes); g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/"), ==, 0); g_assert_cmpint (count_interfaces (c, "/"), ==, 0);
nodes = get_nodes_at (c, "/foo"); nodes = get_nodes_at (c, "/foo");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 2); g_assert_cmpint (g_strv_length (nodes), ==, 2);
g_assert_cmpstr (nodes[0], ==, "boss"); g_assert_cmpstr (nodes[0], ==, "boss");
g_assert_cmpstr (nodes[1], ==, "dyna"); g_assert_cmpstr (nodes[1], ==, "dyna");
@ -1292,25 +1297,25 @@ test_object_registration (void)
g_assert_cmpint (count_interfaces (c, "/foo"), ==, 0); g_assert_cmpint (count_interfaces (c, "/foo"), ==, 0);
nodes = get_nodes_at (c, "/foo/boss"); nodes = get_nodes_at (c, "/foo/boss");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 5); g_assert_cmpint (g_strv_length (nodes), ==, 5);
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "worker1"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker1p1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "worker1p1"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker2")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "worker2"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "interns")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "interns"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "executives")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "executives"));
g_strfreev (nodes); g_strfreev (nodes);
/* any registered object always implement org.freedesktop.DBus.[Peer,Introspectable,Properties] */ /* any registered object always implement org.freedesktop.DBus.[Peer,Introspectable,Properties] */
g_assert_cmpint (count_interfaces (c, "/foo/boss"), ==, 5); g_assert_cmpint (count_interfaces (c, "/foo/boss"), ==, 5);
g_assert (has_interface (c, "/foo/boss", foo_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss", bar_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss", bar_interface_info.name));
/* check subtree nodes - we should have only non_subtree_object in /foo/boss/executives /* check subtree nodes - we should have only non_subtree_object in /foo/boss/executives
* because data.num_subtree_nodes is 0 * because data.num_subtree_nodes is 0
*/ */
nodes = get_nodes_at (c, "/foo/boss/executives"); nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object"));
g_assert_cmpint (g_strv_length (nodes), ==, 1); g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_strfreev (nodes); g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives"), ==, 0); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives"), ==, 0);
@ -1318,41 +1323,41 @@ test_object_registration (void)
/* now change data.num_subtree_nodes and check */ /* now change data.num_subtree_nodes and check */
data.num_subtree_nodes = 2; data.num_subtree_nodes = 2;
nodes = get_nodes_at (c, "/foo/boss/executives"); nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 5); g_assert_cmpint (g_strv_length (nodes), ==, 5);
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp0")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "vp0"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "vp1"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp0")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "evp0"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "evp1"));
/* check that /foo/boss/executives/non_subtree_object is not handled by the /* check that /foo/boss/executives/non_subtree_object is not handled by the
* subtree handlers - we can do this because objects from subtree handlers * subtree handlers - we can do this because objects from subtree handlers
* has exactly one interface and non_subtree_object has two * has exactly one interface and non_subtree_object has two
*/ */
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/non_subtree_object"), ==, 5); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/non_subtree_object"), ==, 5);
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", foo_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/non_subtree_object", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", bar_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/non_subtree_object", bar_interface_info.name));
/* check that the vp and evp objects are handled by the subtree handlers */ /* check that the vp and evp objects are handled by the subtree handlers */
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp0"), ==, 4); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp0"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp1"), ==, 4); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp1"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp0"), ==, 4); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp0"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp1"), ==, 4); g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp1"), ==, 4);
g_assert (has_interface (c, "/foo/boss/executives/vp0", foo_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/vp0", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/vp1", foo_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/vp1", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/evp0", bar_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/evp0", bar_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/evp1", bar_interface_info.name)); g_assert_true (has_interface (c, "/foo/boss/executives/evp1", bar_interface_info.name));
g_strfreev (nodes); g_strfreev (nodes);
data.num_subtree_nodes = 3; data.num_subtree_nodes = 3;
nodes = get_nodes_at (c, "/foo/boss/executives"); nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 7); g_assert_cmpint (g_strv_length (nodes), ==, 7);
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp0")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "vp0"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "vp1"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp2")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "vp2"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp0")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "evp0"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp1")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "evp1"));
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp2")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "evp2"));
g_strfreev (nodes); g_strfreev (nodes);
/* This is to check that a bug (rather, class of bugs) in gdbusconnection.c's /* This is to check that a bug (rather, class of bugs) in gdbusconnection.c's
@ -1362,7 +1367,7 @@ test_object_registration (void)
* where /foo/boss/worker1 reported a child '1', is now fixed. * where /foo/boss/worker1 reported a child '1', is now fixed.
*/ */
nodes = get_nodes_at (c, "/foo/boss/worker1"); nodes = get_nodes_at (c, "/foo/boss/worker1");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 0); g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes); g_strfreev (nodes);
@ -1382,37 +1387,37 @@ test_object_registration (void)
#endif #endif
/* check that unregistering the subtree handler works */ /* check that unregistering the subtree handler works */
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2); g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2);
g_assert_true (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 3);
nodes = get_nodes_at (c, "/foo/boss/executives"); nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 1); g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); g_assert_true (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object"));
g_strfreev (nodes); g_strfreev (nodes);
g_assert (g_dbus_connection_unregister_object (c, boss_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, boss_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, boss_bar_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, boss_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker1_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, worker1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker1p1_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, worker1p1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker2_bar_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, worker2_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern1_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, intern1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern2_bar_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, intern2_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern2_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, intern2_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern3_bar_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, intern3_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_bar_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, non_subtree_object_path_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_foo_reg_id)); g_assert_true (g_dbus_connection_unregister_object (c, non_subtree_object_path_foo_reg_id));
g_main_context_iteration (NULL, FALSE); g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_calls, ==, num_successful_registrations); g_assert_cmpint (data.num_unregistered_calls, ==, num_successful_registrations + num_failed_registrations);
/* check that we no longer export any objects - TODO: it looks like there's a bug in /* check that we no longer export any objects - TODO: it looks like there's a bug in
* libdbus-1 here: libdbus still reports the '/foo' object; so disable the test for now * libdbus-1 here: libdbus still reports the '/foo' object; so disable the test for now
*/ */
#if 0 #if 0
nodes = get_nodes_at (c, "/"); nodes = get_nodes_at (c, "/");
g_assert (nodes != NULL); g_assert_nonnull (nodes);
g_assert_cmpint (g_strv_length (nodes), ==, 0); g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes); g_strfreev (nodes);
#endif #endif
@ -1429,7 +1434,7 @@ test_object_registration_with_closures (void)
error = NULL; error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (c != NULL); g_assert_nonnull (c);
registration_id = g_dbus_connection_register_object_with_closures (c, registration_id = g_dbus_connection_register_object_with_closures (c,
"/foo/boss", "/foo/boss",
@ -1439,11 +1444,11 @@ test_object_registration_with_closures (void)
g_cclosure_new (G_CALLBACK (foo_set_property), NULL, NULL), g_cclosure_new (G_CALLBACK (foo_set_property), NULL, NULL),
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id > 0); g_assert_cmpuint (registration_id, >, 0);
test_dispatch ("/foo/boss", FALSE); test_dispatch ("/foo/boss", FALSE);
g_assert (g_dbus_connection_unregister_object (c, registration_id)); g_assert_true (g_dbus_connection_unregister_object (c, registration_id));
g_object_unref (c); g_object_unref (c);
} }
@ -1490,7 +1495,7 @@ check_interfaces (GDBusConnection *c,
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (proxy != NULL); g_assert_nonnull (proxy);
/* do this async to avoid libdbus-1 deadlocks */ /* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL; xml_data = NULL;
@ -1503,13 +1508,13 @@ check_interfaces (GDBusConnection *c,
(GAsyncReadyCallback) introspect_callback, (GAsyncReadyCallback) introspect_callback,
&xml_data); &xml_data);
g_main_loop_run (loop); g_main_loop_run (loop);
g_assert (xml_data != NULL); g_assert_nonnull (xml_data);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (node_info != NULL); g_assert_nonnull (node_info);
g_assert (node_info->interfaces != NULL); g_assert_nonnull (node_info->interfaces);
for (i = 0; node_info->interfaces[i]; i++) ; for (i = 0; node_info->interfaces[i]; i++) ;
#if 0 #if 0
if (g_strv_length ((gchar**)interfaces) != i - 1) if (g_strv_length ((gchar**)interfaces) != i - 1)
@ -1558,7 +1563,7 @@ test_registered_interfaces (void)
error = NULL; error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (c != NULL); g_assert_nonnull (c);
id1 = g_dbus_connection_register_object (c, id1 = g_dbus_connection_register_object (c,
"/test", "/test",
@ -1568,7 +1573,7 @@ test_registered_interfaces (void)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (id1 > 0); g_assert_cmpuint (id1, >, 0);
id2 = g_dbus_connection_register_object (c, id2 = g_dbus_connection_register_object (c,
"/test", "/test",
(GDBusInterfaceInfo *) &test_interface_info2, (GDBusInterfaceInfo *) &test_interface_info2,
@ -1577,12 +1582,12 @@ test_registered_interfaces (void)
NULL, NULL,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (id2 > 0); g_assert_cmpuint (id2, >, 0);
check_interfaces (c, "/test", interfaces); check_interfaces (c, "/test", interfaces);
g_assert (g_dbus_connection_unregister_object (c, id1)); g_assert_true (g_dbus_connection_unregister_object (c, id1));
g_assert (g_dbus_connection_unregister_object (c, id2)); g_assert_true (g_dbus_connection_unregister_object (c, id2));
g_object_unref (c); g_object_unref (c);
} }
@ -1606,7 +1611,7 @@ test_async_method_call (GDBusConnection *connection,
* but we don't do any during this testcase, so assert that. * but we don't do any during this testcase, so assert that.
*/ */
g_assert_cmpstr (interface_name, ==, "org.freedesktop.DBus.Properties"); g_assert_cmpstr (interface_name, ==, "org.freedesktop.DBus.Properties");
g_assert (g_dbus_method_invocation_get_method_info (invocation) == NULL); g_assert_null (g_dbus_method_invocation_get_method_info (invocation));
property = g_dbus_method_invocation_get_property_info (invocation); property = g_dbus_method_invocation_get_property_info (invocation);
@ -1626,9 +1631,9 @@ test_async_method_call (GDBusConnection *connection,
g_variant_get (parameters, "(&s&s)", &iface_name, &prop_name); g_variant_get (parameters, "(&s&s)", &iface_name, &prop_name);
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property != NULL); g_assert_nonnull (property);
g_assert_cmpstr (prop_name, ==, property->name); g_assert_cmpstr (prop_name, ==, property->name);
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE); g_assert_true (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", g_variant_new_string (prop_name))); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", g_variant_new_string (prop_name)));
} }
@ -1639,10 +1644,10 @@ test_async_method_call (GDBusConnection *connection,
g_variant_get (parameters, "(&s&sv)", &iface_name, &prop_name, &value); g_variant_get (parameters, "(&s&sv)", &iface_name, &prop_name, &value);
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property != NULL); g_assert_nonnull (property);
g_assert_cmpstr (prop_name, ==, property->name); g_assert_cmpstr (prop_name, ==, property->name);
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE); g_assert_true (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE (property->signature))); g_assert_true (g_variant_is_of_type (value, G_VARIANT_TYPE (property->signature)));
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
g_variant_unref (value); g_variant_unref (value);
} }
@ -1653,7 +1658,7 @@ test_async_method_call (GDBusConnection *connection,
g_variant_get (parameters, "(&s)", &iface_name); g_variant_get (parameters, "(&s)", &iface_name);
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property == NULL); g_assert_null (property);
g_dbus_method_invocation_return_value (invocation, g_dbus_method_invocation_return_value (invocation,
g_variant_new_parsed ("({ 'PropertyUno': < 'uno' >," g_variant_new_parsed ("({ 'PropertyUno': < 'uno' >,"
" 'NotWritable': < 'notwrite' > },)")); " 'NotWritable': < 'notwrite' > },)"));
@ -1678,14 +1683,14 @@ ensure_result_cb (GObject *source,
if (user_data == NULL) if (user_data == NULL)
{ {
/* Expected an error */ /* Expected an error */
g_assert (reply == NULL); g_assert_null (reply);
} }
else else
{ {
/* Expected a reply of a particular format. */ /* Expected a reply of a particular format. */
gchar *str; gchar *str;
g_assert (reply != NULL); g_assert_nonnull (reply);
str = g_variant_print (reply, TRUE); str = g_variant_print (reply, TRUE);
g_assert_cmpstr (str, ==, (const gchar *) user_data); g_assert_cmpstr (str, ==, (const gchar *) user_data);
g_free (str); g_free (str);
@ -1728,20 +1733,20 @@ test_async_properties (void)
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (c != NULL); g_assert_nonnull (c);
registration_id = g_dbus_connection_register_object (c, registration_id = g_dbus_connection_register_object (c,
"/foo", "/foo",
(GDBusInterfaceInfo *) &foo_interface_info, (GDBusInterfaceInfo *) &foo_interface_info,
&vtable, NULL, NULL, &error); &vtable, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id); g_assert_cmpuint (registration_id, !=, 0);
registration_id2 = g_dbus_connection_register_object (c, registration_id2 = g_dbus_connection_register_object (c,
"/foo", "/foo",
(GDBusInterfaceInfo *) &foo2_interface_info, (GDBusInterfaceInfo *) &foo2_interface_info,
&vtable, NULL, NULL, &error); &vtable, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (registration_id); g_assert_cmpuint (registration_id, !=, 0);
test_async_case (c, NULL, "random", "()"); test_async_case (c, NULL, "random", "()");

View File

@ -98,7 +98,7 @@ _xdg_glob_list_free (XdgGlobList *glob_list)
static XdgGlobList * static XdgGlobList *
_xdg_glob_list_append (XdgGlobList *glob_list, _xdg_glob_list_append (XdgGlobList *glob_list,
void *data, const char *data,
const char *mime_type, const char *mime_type,
int weight, int weight,
int case_sensitive) int case_sensitive)
@ -117,8 +117,8 @@ _xdg_glob_list_append (XdgGlobList *glob_list,
} }
new_element = _xdg_glob_list_new (); new_element = _xdg_glob_list_new ();
new_element->data = data; new_element->data = strdup (data);
new_element->mime_type = mime_type; new_element->mime_type = strdup (mime_type);
new_element->weight = weight; new_element->weight = weight;
new_element->case_sensitive = case_sensitive; new_element->case_sensitive = case_sensitive;
if (glob_list == NULL) if (glob_list == NULL)
@ -576,13 +576,13 @@ _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash,
switch (type) switch (type)
{ {
case XDG_GLOB_LITERAL: case XDG_GLOB_LITERAL:
glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type), weight, case_sensitive); glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, glob, mime_type, weight, case_sensitive);
break; break;
case XDG_GLOB_SIMPLE: case XDG_GLOB_SIMPLE:
glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight, case_sensitive); glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight, case_sensitive);
break; break;
case XDG_GLOB_FULL: case XDG_GLOB_FULL:
glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type), weight, case_sensitive); glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, glob, mime_type, weight, case_sensitive);
break; break;
} }
} }

View File

@ -339,7 +339,7 @@ gi_function_invoker_new_for_address (void *addr,
return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_args, return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_args,
gi_callable_info_get_ffi_return_type (info), gi_callable_info_get_ffi_return_type (info),
atypes) == FFI_OK; g_steal_pointer (&atypes)) == FFI_OK;
} }
/** /**
@ -409,10 +409,15 @@ gi_callable_info_create_closure (GICallableInfo *callable_info,
status = ffi_prep_cif (cif, FFI_DEFAULT_ABI, n_args, status = ffi_prep_cif (cif, FFI_DEFAULT_ABI, n_args,
gi_callable_info_get_ffi_return_type (callable_info), gi_callable_info_get_ffi_return_type (callable_info),
atypes); atypes);
/* Explicitly store atypes to satisfy static analysers, which cant see inside
* ffi_prep_cif(), and hence assume that its leaked. */
cif->arg_types = g_steal_pointer (&atypes);
if (status != FFI_OK) if (status != FFI_OK)
{ {
g_warning ("ffi_prep_cif failed: %d", status); g_warning ("ffi_prep_cif failed: %d", status);
ffi_closure_free (closure); gi_callable_info_destroy_closure (callable_info, &closure->ffi_closure);
return NULL; return NULL;
} }
@ -420,7 +425,7 @@ gi_callable_info_create_closure (GICallableInfo *callable_info,
if (status != FFI_OK) if (status != FFI_OK)
{ {
g_warning ("ffi_prep_closure failed: %d", status); g_warning ("ffi_prep_closure failed: %d", status);
ffi_closure_free (closure); gi_callable_info_destroy_closure (callable_info, &closure->ffi_closure);
return NULL; return NULL;
} }

View File

@ -594,8 +594,7 @@ gi_ir_node_get_full_size_internal (GIIrNode *parent,
GList *l; GList *l;
size_t size, n; size_t size, n;
if (node == NULL && parent != NULL) g_assert (node != NULL);
g_error ("Caught NULL node, parent=%s", parent->name);
g_debug ("node %p type '%s'", node, g_debug ("node %p type '%s'", node,
gi_ir_node_type_to_string (node->type)); gi_ir_node_type_to_string (node->type));

View File

@ -1811,6 +1811,8 @@ do_posix_spawn (const gchar * const *argv,
goto out_close_fds; goto out_close_fds;
duped_source_fds = g_new (gint, n_fds); duped_source_fds = g_new (gint, n_fds);
for (i = 0; i < n_fds; i++)
duped_source_fds[i] = -1; /* initialise in case dupfd_cloexec() fails below */
for (i = 0; i < n_fds; i++) for (i = 0; i < n_fds; i++)
{ {
duped_source_fds[i] = dupfd_cloexec (source_fds[i], max_target_fd + 1); duped_source_fds[i] = dupfd_cloexec (source_fds[i], max_target_fd + 1);

View File

@ -762,7 +762,8 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
* Dont bother checking if the highest known-good offset is lower than the * Dont bother checking if the highest known-good offset is lower than the
* highest checked offset, as that means theres an invalid element at that * highest checked offset, as that means theres an invalid element at that
* index, so theres no need to check further. */ * index, so theres no need to check further. */
if (index_ > value.checked_offsets_up_to && if (offsets.array != NULL &&
index_ > value.checked_offsets_up_to &&
value.ordered_offsets_up_to == value.checked_offsets_up_to) value.ordered_offsets_up_to == value.checked_offsets_up_to)
{ {
switch (offsets.offset_size) switch (offsets.offset_size)

View File

@ -1018,7 +1018,7 @@ param_value_array_validate (GParamSpec *pspec,
guint changed = 0; guint changed = 0;
if (!value->data[0].v_pointer && aspec->fixed_n_elements) if (!value->data[0].v_pointer && aspec->fixed_n_elements)
value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements); value_array = value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
if (value->data[0].v_pointer) if (value->data[0].v_pointer)
{ {

View File

@ -549,6 +549,7 @@ if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
'-Wmisleading-indentation', '-Wmisleading-indentation',
'-Wmissing-field-initializers', '-Wmissing-field-initializers',
'-Wnonnull', '-Wnonnull',
'-Wnull-dereference',
'-Wunused', '-Wunused',
# Due to maintained deprecated code, we do not want to see unused parameters # Due to maintained deprecated code, we do not want to see unused parameters
'-Wno-unused-parameter', '-Wno-unused-parameter',