From f55897af74ac072d3447e5cf513d0f4718b142c7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 10 Oct 2007 11:41:57 +0100 Subject: Use DBUS_ERROR_INIT instead of dbus_error_init wherever it's clearly equivalent --- dbus/dbus-address.c | 6 ++---- dbus/dbus-auth-script.c | 3 +-- dbus/dbus-auth-util.c | 3 +-- dbus/dbus-connection.c | 14 ++++---------- dbus/dbus-internals.c | 8 +++----- dbus/dbus-keyring.c | 13 +++++-------- dbus/dbus-message-util.c | 15 +++++---------- dbus/dbus-server.c | 15 ++++++--------- dbus/dbus-sha.c | 5 ++--- dbus/dbus-spawn-win.c | 32 ++++++++------------------------ dbus/dbus-spawn.c | 38 ++++++++++---------------------------- dbus/dbus-sysdeps-util-win.c | 3 +-- dbus/dbus-transport-socket.c | 3 +-- dbus/dbus-transport.c | 5 ++--- dbus/dbus-userdb.c | 4 +--- 15 files changed, 52 insertions(+), 115 deletions(-) diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c index 0b87b8e6..28e88424 100644 --- a/dbus/dbus-address.c +++ b/dbus/dbus-address.c @@ -698,12 +698,10 @@ dbus_bool_t _dbus_address_test (void) { DBusAddressEntry **entries; - int len; - DBusError error; + int len; + DBusError error = DBUS_ERROR_INIT; int i; - dbus_error_init (&error); - i = 0; while (i < _DBUS_N_ELEMENTS (escape_tests)) { diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c index a4102af3..93d6f78c 100644 --- a/dbus/dbus-auth-script.c +++ b/dbus/dbus-auth-script.c @@ -244,7 +244,7 @@ dbus_bool_t _dbus_auth_script_run (const DBusString *filename) { DBusString file; - DBusError error; + DBusError error = DBUS_ERROR_INIT; DBusString line; dbus_bool_t retval; int line_no; @@ -276,7 +276,6 @@ _dbus_auth_script_run (const DBusString *filename) return FALSE; } - dbus_error_init (&error); if (!_dbus_file_get_contents (&file, filename, &error)) { _dbus_warn ("Getting contents of %s failed: %s\n", _dbus_string_get_const_data (filename), error.message); diff --git a/dbus/dbus-auth-util.c b/dbus/dbus-auth-util.c index 45627896..e5019042 100644 --- a/dbus/dbus-auth-util.c +++ b/dbus/dbus-auth-util.c @@ -44,7 +44,7 @@ process_test_subdir (const DBusString *test_base_dir, DBusString filename; DBusDirIter *dir; dbus_bool_t retval; - DBusError error; + DBusError error = DBUS_ERROR_INIT; retval = FALSE; dir = NULL; @@ -65,7 +65,6 @@ process_test_subdir (const DBusString *test_base_dir, if (!_dbus_string_init (&filename)) _dbus_assert_not_reached ("didn't allocate filename string\n"); - dbus_error_init (&error); dir = _dbus_directory_open (&test_directory, &error); if (dir == NULL) { diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index b6ecc36d..e6848c1d 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -1709,8 +1709,8 @@ _dbus_connection_open_internal (const char *address, { DBusConnection *connection; DBusAddressEntry **entries; - DBusError tmp_error; - DBusError first_error; + DBusError tmp_error = DBUS_ERROR_INIT; + DBusError first_error = DBUS_ERROR_INIT; int len, i; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1725,8 +1725,6 @@ _dbus_connection_open_internal (const char *address, connection = NULL; - dbus_error_init (&tmp_error); - dbus_error_init (&first_error); for (i = 0; i < len; i++) { if (shared) @@ -5327,15 +5325,13 @@ dbus_connection_register_object_path (DBusConnection *connection, { char **decomposed_path; dbus_bool_t retval; - DBusError error; + DBusError error = DBUS_ERROR_INIT; _dbus_return_val_if_fail (connection != NULL, FALSE); _dbus_return_val_if_fail (path != NULL, FALSE); _dbus_return_val_if_fail (path[0] == '/', FALSE); _dbus_return_val_if_fail (vtable != NULL, FALSE); - dbus_error_init (&error); - if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL)) return FALSE; @@ -5430,15 +5426,13 @@ dbus_connection_register_fallback (DBusConnection *connection, { char **decomposed_path; dbus_bool_t retval; - DBusError error; + DBusError error = DBUS_ERROR_INIT; _dbus_return_val_if_fail (connection != NULL, FALSE); _dbus_return_val_if_fail (path != NULL, FALSE); _dbus_return_val_if_fail (path[0] == '/', FALSE); _dbus_return_val_if_fail (vtable != NULL, FALSE); - dbus_error_init (&error); - if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL)) return FALSE; diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index fdc08d3c..c99bee1a 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -668,9 +668,7 @@ _dbus_read_uuid_file (const DBusString *filename, dbus_bool_t create_if_not_found, DBusError *error) { - DBusError read_error; - - dbus_error_init (&read_error); + DBusError read_error = DBUS_ERROR_INIT; if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error)) return TRUE; @@ -719,8 +717,8 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str) _DBUS_LOCK (machine_uuid); if (machine_uuid_initialized_generation != _dbus_current_generation) { - DBusError error; - dbus_error_init (&error); + DBusError error = DBUS_ERROR_INIT; + if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, &error)) { diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c index 4b7182df..de6a5ea4 100644 --- a/dbus/dbus-keyring.c +++ b/dbus/dbus-keyring.c @@ -201,9 +201,8 @@ _dbus_keyring_lock (DBusKeyring *keyring) n_timeouts = 0; while (n_timeouts < MAX_LOCK_TIMEOUTS) { - DBusError error; + DBusError error = DBUS_ERROR_INIT; - dbus_error_init (&error); if (_dbus_create_file_exclusively (&keyring->filename_lock, &error)) break; @@ -219,13 +218,11 @@ _dbus_keyring_lock (DBusKeyring *keyring) if (n_timeouts == MAX_LOCK_TIMEOUTS) { - DBusError error; - + DBusError error = DBUS_ERROR_INIT; + _dbus_verbose ("Lock file timed out %d times, assuming stale\n", n_timeouts); - dbus_error_init (&error); - if (!_dbus_delete_file (&keyring->filename_lock, &error)) { _dbus_verbose ("Couldn't delete old lock file: %s\n", @@ -250,8 +247,8 @@ _dbus_keyring_lock (DBusKeyring *keyring) static void _dbus_keyring_unlock (DBusKeyring *keyring) { - DBusError error; - dbus_error_init (&error); + DBusError error = DBUS_ERROR_INIT; + if (!_dbus_delete_file (&keyring->filename_lock, &error)) { _dbus_warn ("Failed to delete lock file: %s\n", diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c index f82d4f4f..0fa010cc 100644 --- a/dbus/dbus-message-util.c +++ b/dbus/dbus-message-util.c @@ -276,12 +276,11 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename, DBusString *data) { dbus_bool_t retval; - DBusError error; - + DBusError error = DBUS_ERROR_INIT; + retval = FALSE; _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename)); - dbus_error_init (&error); if (!_dbus_file_get_contents (data, filename, &error)) { _dbus_warn ("Could not load message file %s: %s\n", @@ -450,7 +449,7 @@ process_test_subdir (const DBusString *test_base_dir, DBusString filename; DBusDirIter *dir; dbus_bool_t retval; - DBusError error; + DBusError error = DBUS_ERROR_INIT; retval = FALSE; dir = NULL; @@ -471,7 +470,6 @@ process_test_subdir (const DBusString *test_base_dir, if (!_dbus_string_init (&filename)) _dbus_assert_not_reached ("didn't allocate filename string\n"); - dbus_error_init (&error); dir = _dbus_directory_open (&test_directory, &error); if (dir == NULL) { @@ -701,7 +699,7 @@ static void verify_test_message (DBusMessage *message) { DBusMessageIter iter; - DBusError error; + DBusError error = DBUS_ERROR_INIT; dbus_int16_t our_int16; dbus_uint16_t our_uint16; dbus_int32_t our_int; @@ -734,7 +732,6 @@ verify_test_message (DBusMessage *message) dbus_message_iter_init (message, &iter); - dbus_error_init (&error); if (!dbus_message_iter_get_args (&iter, &error, DBUS_TYPE_INT16, &our_int16, DBUS_TYPE_UINT16, &our_uint16, @@ -1226,12 +1223,10 @@ _dbus_message_test (const char *test_data_dir) /* Marshal and demarshal the message. */ DBusMessage *message2; - DBusError error; + DBusError error = DBUS_ERROR_INIT; char *marshalled = NULL; int len = 0; - dbus_error_init (&error); - if (!dbus_message_marshal (message, &marshalled, &len)) _dbus_assert_not_reached ("failed to marshal message"); diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 755fadad..f04829b6 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -543,7 +543,7 @@ dbus_server_listen (const char *address, DBusServer *server; DBusAddressEntry **entries; int len, i; - DBusError first_connect_error; + DBusError first_connect_error = DBUS_ERROR_INIT; dbus_bool_t handled_once; _dbus_return_val_if_fail (address != NULL, NULL); @@ -553,9 +553,8 @@ dbus_server_listen (const char *address, return NULL; server = NULL; - dbus_error_init (&first_connect_error); handled_once = FALSE; - + for (i = 0; i < len; i++) { int j; @@ -563,9 +562,8 @@ dbus_server_listen (const char *address, for (j = 0; j < (int) _DBUS_N_ELEMENTS (listen_funcs); ++j) { DBusServerListenResult result; - DBusError tmp_error; - - dbus_error_init (&tmp_error); + DBusError tmp_error = DBUS_ERROR_INIT; + result = (* listen_funcs[j].func) (entries[i], &server, &tmp_error); @@ -1167,11 +1165,10 @@ _dbus_server_test (void) for (i = 0; i < _DBUS_N_ELEMENTS (valid_addresses); i++) { - DBusError error; + DBusError error = DBUS_ERROR_INIT; char *address; char *id; - - dbus_error_init (&error); + server = dbus_server_listen (valid_addresses[i], &error); if (server == NULL) { diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c index 9f1cdbb2..8ec50b6f 100644 --- a/dbus/dbus-sha.c +++ b/dbus/dbus-sha.c @@ -745,8 +745,8 @@ process_test_data (const char *test_data_dir) int line_no; dbus_bool_t retval; int success_count; - DBusError error; - + DBusError error = DBUS_ERROR_INIT; + retval = FALSE; if (!_dbus_string_init (&tests_file)) @@ -778,7 +778,6 @@ process_test_data (const char *test_data_dir) if (!_dbus_concat_dir_and_file (&results_file, &tmp)) _dbus_assert_not_reached ("no memory"); - dbus_error_init (&error); if (!_dbus_file_get_contents (&tests, &tests_file, &error)) { fprintf (stderr, "could not load test data file %s: %s\n", diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 5ab85164..c2ad16bb 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -621,12 +621,8 @@ static dbus_bool_t check_spawn_nonexistent (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching nonexistent binary */ @@ -666,12 +662,8 @@ static dbus_bool_t check_spawn_segfault (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching segfault binary */ @@ -711,12 +703,8 @@ static dbus_bool_t check_spawn_exit (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching exit failure binary */ @@ -756,12 +744,8 @@ static dbus_bool_t check_spawn_and_kill (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching sleeping binary then killing it */ diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index 810536fd..eaa9ef15 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -366,11 +366,9 @@ read_data (DBusBabysitter *sitter, { int what; int got; - DBusError error; + DBusError error = DBUS_ERROR_INIT; ReadStatus r; - - dbus_error_init (&error); - + r = read_ints (fd, &what, 1, &got, &error); switch (r) @@ -1238,12 +1236,8 @@ static dbus_bool_t check_spawn_nonexistent (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching nonexistent binary */ @@ -1283,12 +1277,8 @@ static dbus_bool_t check_spawn_segfault (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching segfault binary */ @@ -1328,12 +1318,8 @@ static dbus_bool_t check_spawn_exit (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching exit failure binary */ @@ -1373,12 +1359,8 @@ static dbus_bool_t check_spawn_and_kill (void *data) { char *argv[4] = { NULL, NULL, NULL, NULL }; - DBusBabysitter *sitter; - DBusError error; - - sitter = NULL; - - dbus_error_init (&error); + DBusBabysitter *sitter = NULL; + DBusError error = DBUS_ERROR_INIT; /*** Test launching sleeping binary then killing it */ diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index e4a30ba1..8608ad0e 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -917,9 +917,8 @@ void _dbus_win_warn_win_error (const char *message, int code) { - DBusError error; + DBusError error = DBUS_ERROR_INIT; - dbus_error_init (&error); _dbus_win_set_error_from_win_error (&error, code); _dbus_warn ("%s: %s\n", message, error.message); dbus_error_free (&error); diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c index f6d0e9c2..05e3f3ae 100644 --- a/dbus/dbus-transport-socket.c +++ b/dbus/dbus-transport-socket.c @@ -338,12 +338,11 @@ exchange_credentials (DBusTransport *transport, dbus_bool_t do_writing) { DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport; - DBusError error; + DBusError error = DBUS_ERROR_INIT; _dbus_verbose ("exchange_credentials: do_reading = %d, do_writing = %d\n", do_reading, do_writing); - dbus_error_init (&error); if (do_writing && transport->send_credentials_pending) { if (_dbus_send_credentials_socket (socket_transport->fd, diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index ddd20315..313cd417 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -354,8 +354,8 @@ _dbus_transport_open (DBusAddressEntry *entry, const char *expected_guid_orig; char *expected_guid; int i; - DBusError tmp_error; - + DBusError tmp_error = DBUS_ERROR_INIT; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); transport = NULL; @@ -368,7 +368,6 @@ _dbus_transport_open (DBusAddressEntry *entry, return NULL; } - dbus_error_init (&tmp_error); for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i) { DBusTransportOpenResult result; diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index aded538f..0e430b2b 100644 --- a/dbus/dbus-userdb.c +++ b/dbus/dbus-userdb.c @@ -239,15 +239,13 @@ init_system_db (void) if (system_db == NULL) { - DBusError error; + DBusError error = DBUS_ERROR_INIT; const DBusUserInfo *info; system_db = _dbus_user_database_new (); if (system_db == NULL) return FALSE; - dbus_error_init (&error); - if (!_dbus_user_database_get_uid (system_db, _dbus_getuid (), &info, -- cgit