From fa05de9230d62e7c427b5313796fc6ccd4d0ff60 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 31 Mar 2003 20:56:29 +0000 Subject: 2003-03-31 Havoc Pennington Fix some annoying DBusString API and fix all affected code. * dbus/dbus-string.c (_dbus_string_init): get rid of annoying max_length argument (_dbus_string_get_data): change to return string instead of using an out param (_dbus_string_get_const_data): ditto (_dbus_string_get_data_len): ditto (_dbus_string_get_const_data_len): ditto --- ChangeLog | 12 ++++ bus/activation.c | 21 ++---- bus/bus.c | 2 +- bus/config-loader-expat.c | 8 +-- bus/config-parser.c | 26 +++---- bus/connection.c | 9 +-- bus/desktop-file.c | 4 +- bus/dispatch.c | 4 +- bus/driver.c | 2 +- bus/main.c | 6 +- bus/services.c | 13 +--- bus/test.c | 2 +- dbus/dbus-address.c | 18 ++--- dbus/dbus-auth-script.c | 59 ++++++---------- dbus/dbus-auth.c | 112 ++++++++++++------------------ dbus/dbus-keyring.c | 26 ++++--- dbus/dbus-marshal.c | 19 +++-- dbus/dbus-md5.c | 4 +- dbus/dbus-message-builder.c | 38 ++++------ dbus/dbus-message.c | 72 ++++++++----------- dbus/dbus-server-debug-pipe.c | 4 +- dbus/dbus-server-debug.c | 2 +- dbus/dbus-server-unix.c | 4 +- dbus/dbus-sha.c | 71 +++++++------------ dbus/dbus-string.c | 158 +++++++++++++++++++++--------------------- dbus/dbus-string.h | 15 ++-- dbus/dbus-sysdeps.c | 60 ++++++++-------- dbus/dbus-transport-debug.c | 2 +- dbus/dbus-transport-unix.c | 10 ++- dbus/dbus-transport.c | 2 +- test/break-loader.c | 25 +++---- test/unbase64.c | 6 +- 32 files changed, 347 insertions(+), 469 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b6d6fc0..b3ffa075 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-03-31 Havoc Pennington + + Fix some annoying DBusString API and fix all affected code. + + * dbus/dbus-string.c (_dbus_string_init): get rid of annoying + max_length argument + (_dbus_string_get_data): change to return string instead of using + an out param + (_dbus_string_get_const_data): ditto + (_dbus_string_get_data_len): ditto + (_dbus_string_get_const_data_len): ditto + 2003-03-31 Havoc Pennington * bus/main.c (main): fix up the command line arguments to be nicer diff --git a/bus/activation.c b/bus/activation.c index 8def99b9..fe069c79 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -204,13 +204,13 @@ load_directory (BusActivation *activation, iter = NULL; desktop_file = NULL; - if (!_dbus_string_init (&filename, _DBUS_INT_MAX)) + if (!_dbus_string_init (&filename)) { BUS_SET_OOM (error); return FALSE; } - if (!_dbus_string_init (&full_path, _DBUS_INT_MAX)) + if (!_dbus_string_init (&full_path)) { BUS_SET_OOM (error); _dbus_string_free (&filename); @@ -244,10 +244,8 @@ load_directory (BusActivation *activation, if (!_dbus_string_ends_with_c_str (&filename, ".service")) { - const char *filename_c; - _dbus_string_get_const_data (&filename, &filename_c); _dbus_verbose ("Skipping non-.service file %s\n", - filename_c); + _dbus_string_get_const_data (&filename)); continue; } @@ -255,11 +253,8 @@ load_directory (BusActivation *activation, if (desktop_file == NULL) { - const char *full_path_c; - - _dbus_string_get_const_data (&full_path, &full_path_c); - - _dbus_verbose ("Could not load %s: %s\n", full_path_c, + _dbus_verbose ("Could not load %s: %s\n", + _dbus_string_get_const_data (&full_path), tmp_error.message); if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) @@ -274,15 +269,11 @@ load_directory (BusActivation *activation, if (!add_desktop_file_entry (activation, desktop_file, &tmp_error)) { - const char *full_path_c; - bus_desktop_file_free (desktop_file); desktop_file = NULL; - - _dbus_string_get_const_data (&full_path, &full_path_c); _dbus_verbose ("Could not add %s to activation entry list: %s\n", - full_path_c, tmp_error.message); + _dbus_string_get_const_data (&full_path), tmp_error.message); if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) { diff --git a/bus/bus.c b/bus/bus.c index 6d4f71b3..ca9802c0 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -184,7 +184,7 @@ bus_context_new (const DBusString *config_file, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&full_address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&full_address)) return NULL; parser = NULL; diff --git a/bus/config-loader-expat.c b/bus/config-loader-expat.c index 9988fb69..9e6de5e2 100644 --- a/bus/config-loader-expat.c +++ b/bus/config-loader-expat.c @@ -178,9 +178,9 @@ bus_config_load (const DBusString *file, context.error = error; context.failed = FALSE; - _dbus_string_get_const_data (file, &filename); + filename = _dbus_string_get_const_data (file); - if (!_dbus_string_init (&context.content, _DBUS_INT_MAX)) + if (!_dbus_string_init (&context.content)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; @@ -212,7 +212,7 @@ bus_config_load (const DBusString *file, DBusString data; const char *data_str; - if (!_dbus_string_init (&data, _DBUS_INT_MAX)) + if (!_dbus_string_init (&data)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed; @@ -224,7 +224,7 @@ bus_config_load (const DBusString *file, goto failed; } - _dbus_string_get_const_data (&data, &data_str); + data_str = _dbus_string_get_const_data (&data); if (!XML_Parse (expat, data_str, _dbus_string_get_length (&data), TRUE)) { diff --git a/bus/config-parser.c b/bus/config-parser.c index bf4f6f7b..39239888 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -941,7 +941,7 @@ process_test_subdir (const DBusString *test_base_dir, retval = FALSE; dir = NULL; - if (!_dbus_string_init (&test_directory, _DBUS_INT_MAX)) + if (!_dbus_string_init (&test_directory)) _dbus_assert_not_reached ("didn't allocate test_directory\n"); _dbus_string_init_const (&filename, subdir); @@ -954,16 +954,15 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_assert_not_reached ("couldn't allocate full path"); _dbus_string_free (&filename); - if (!_dbus_string_init (&filename, _DBUS_INT_MAX)) + 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) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); - _dbus_warn ("Could not open %s: %s\n", s, + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), error.message); dbus_error_free (&error); goto failed; @@ -977,7 +976,7 @@ process_test_subdir (const DBusString *test_base_dir, DBusString full_path; LoaderOomData d; - if (!_dbus_string_init (&full_path, _DBUS_INT_MAX)) + if (!_dbus_string_init (&full_path)) _dbus_assert_not_reached ("couldn't init string"); if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) @@ -988,19 +987,13 @@ process_test_subdir (const DBusString *test_base_dir, if (!_dbus_string_ends_with_c_str (&full_path, ".conf")) { - const char *filename_c; - _dbus_string_get_const_data (&filename, &filename_c); _dbus_verbose ("Skipping non-.conf file %s\n", - filename_c); + _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); goto next; } - { - const char *s; - _dbus_string_get_const_data (&filename, &s); - printf (" %s\n", s); - } + printf (" %s\n", _dbus_string_get_const_data (&filename)); _dbus_verbose (" expecting %s\n", validity == VALID ? "valid" : @@ -1017,10 +1010,9 @@ process_test_subdir (const DBusString *test_base_dir, if (dbus_error_is_set (&error)) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); _dbus_warn ("Could not get next file in %s: %s\n", - s, error.message); + _dbus_string_get_const_data (&test_directory), + error.message); dbus_error_free (&error); goto failed; } diff --git a/bus/connection.c b/bus/connection.c index ee7d183c..3d83d96c 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -732,20 +732,17 @@ dbus_bool_t bus_connection_set_name (DBusConnection *connection, const DBusString *name) { - const char *c_name; BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); _dbus_assert (d != NULL); _dbus_assert (d->name == NULL); - _dbus_string_get_const_data (name, &c_name); - - d->name = _dbus_strdup (c_name); - - if (d->name == NULL) + if (!_dbus_string_copy_data (name, &d->name)) return FALSE; + _dbus_assert (d->name != NULL); + _dbus_verbose ("Name %s assigned to %p\n", d->name, connection); return TRUE; diff --git a/bus/desktop-file.c b/bus/desktop-file.c index 13b709d2..08af768e 100644 --- a/bus/desktop-file.c +++ b/bus/desktop-file.c @@ -514,7 +514,7 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error) return FALSE; } - if (!_dbus_string_init (&key, key_end - key_start)) + if (!_dbus_string_init (&key)) { parser_free (parser); return FALSE; @@ -613,7 +613,7 @@ bus_desktop_file_load (DBusString *filename, return NULL; } - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) return NULL; if (!_dbus_file_get_contents (&str, filename, error)) diff --git a/bus/dispatch.c b/bus/dispatch.c index e75d8e6d..52214dbf 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -110,7 +110,7 @@ send_service_nonexistent_error (BusTransaction *transaction, * bounce back an error message. */ - if (!_dbus_string_init (&error_message, _DBUS_INT_MAX)) + if (!_dbus_string_init (&error_message)) { BUS_SET_OOM (error); return FALSE; @@ -125,7 +125,7 @@ send_service_nonexistent_error (BusTransaction *transaction, return FALSE; } - _dbus_string_get_const_data (&error_message, &error_str); + error_str = _dbus_string_get_const_data (&error_message); error_reply = dbus_message_new_error_reply (in_reply_to, DBUS_ERROR_SERVICE_DOES_NOT_EXIST, error_str); diff --git a/bus/driver.c b/bus/driver.c index 4946fd6a..8749bc13 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -278,7 +278,7 @@ bus_driver_handle_hello (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&unique_name, _DBUS_INT_MAX)) + if (!_dbus_string_init (&unique_name)) { BUS_SET_OOM (error); return FALSE; diff --git a/bus/main.c b/bus/main.c index ae625489..fcde3493 100644 --- a/bus/main.c +++ b/bus/main.c @@ -51,10 +51,8 @@ check_two_config_files (const DBusString *config_file, { if (_dbus_string_get_length (config_file) > 0) { - const char *s; - _dbus_string_get_const_data (config_file, &s); fprintf (stderr, "--%s specified but configuration file %s already requested\n", - extra_arg, s); + extra_arg, _dbus_string_get_const_data (config_file)); exit (1); } } @@ -68,7 +66,7 @@ main (int argc, char **argv) const char *prev_arg; int i; - if (!_dbus_string_init (&config_file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&config_file)) return 1; prev_arg = NULL; diff --git a/bus/services.c b/bus/services.c index d3ab1e59..8d4221fb 100644 --- a/bus/services.c +++ b/bus/services.c @@ -107,13 +107,10 @@ BusService* bus_registry_lookup (BusRegistry *registry, const DBusString *service_name) { - const char *c_name; BusService *service; - - _dbus_string_get_const_data (service_name, &c_name); service = _dbus_hash_table_lookup_string (registry->service_hash, - c_name); + _dbus_string_get_const_data (service_name)); return service; } @@ -125,18 +122,15 @@ bus_registry_ensure (BusRegistry *registry, BusTransaction *transaction, DBusError *error) { - const char *c_name; BusService *service; _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_assert (owner_if_created != NULL); _dbus_assert (transaction != NULL); - - _dbus_string_get_const_data (service_name, &c_name); service = _dbus_hash_table_lookup_string (registry->service_hash, - c_name); + _dbus_string_get_const_data (service_name)); if (service != NULL) return service; @@ -149,8 +143,7 @@ bus_registry_ensure (BusRegistry *registry, service->registry = registry; - service->name = _dbus_strdup (c_name); - if (service->name == NULL) + if (!_dbus_string_copy_data (service_name, &service->name)) { _dbus_mem_pool_dealloc (registry->service_pool, service); BUS_SET_OOM (error); diff --git a/bus/test.c b/bus/test.c index c492cccc..d6697085 100644 --- a/bus/test.c +++ b/bus/test.c @@ -296,7 +296,7 @@ bus_context_new_test (const DBusString *test_data_dir, DBusString relative; BusContext *context; - if (!_dbus_string_init (&config_file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&config_file)) { _dbus_warn ("No memory\n"); return NULL; diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c index 5effe4d1..d3099222 100644 --- a/dbus/dbus-address.c +++ b/dbus/dbus-address.c @@ -97,7 +97,7 @@ create_entry (void) if (entry == NULL) return NULL; - if (!_dbus_string_init (&entry->method, _DBUS_INT_MAX)) + if (!_dbus_string_init (&entry->method)) { dbus_free (entry); return NULL; @@ -116,11 +116,7 @@ create_entry (void) const char * dbus_address_entry_get_method (DBusAddressEntry *entry) { - const char *method; - - _dbus_string_get_const_data (&entry->method, &method); - - return method; + return _dbus_string_get_const_data (&entry->method); } /** @@ -144,12 +140,8 @@ dbus_address_entry_get_value (DBusAddressEntry *entry, _dbus_assert (values != NULL); if (_dbus_string_equal_c_str (keys->data, key)) - { - const char *str; + return _dbus_string_get_const_data (values->data); - _dbus_string_get_const_data (values->data, &str); - return str; - } keys = _dbus_list_get_next_link (&entry->keys, keys); values = _dbus_list_get_next_link (&entry->values, values); } @@ -268,7 +260,7 @@ dbus_parse_address (const char *address, goto error; } - if (!_dbus_string_init (key, _DBUS_INT_MAX)) + if (!_dbus_string_init (key)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); dbus_free (key); @@ -277,7 +269,7 @@ dbus_parse_address (const char *address, goto error; } - if (!_dbus_string_init (value, _DBUS_INT_MAX)) + if (!_dbus_string_init (value)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); _dbus_string_free (key); diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c index 3aaf5688..b8015c2d 100644 --- a/dbus/dbus-auth-script.c +++ b/dbus/dbus-auth-script.c @@ -198,16 +198,16 @@ _dbus_auth_script_run (const DBusString *filename) _dbus_string_init_const (&context, "org_freedesktop_test"); - if (!_dbus_string_init (&file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&file)) return FALSE; - if (!_dbus_string_init (&line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&line)) { _dbus_string_free (&file); return FALSE; } - if (!_dbus_string_init (&from_auth, _DBUS_INT_MAX)) + if (!_dbus_string_init (&from_auth)) { _dbus_string_free (&file); _dbus_string_free (&line); @@ -216,10 +216,8 @@ _dbus_auth_script_run (const DBusString *filename) dbus_error_init (&error); if (!_dbus_file_get_contents (&file, filename, &error)) { - const char *s; - _dbus_string_get_const_data (filename, &s); _dbus_warn ("Getting contents of %s failed: %s\n", - s, error.message); + _dbus_string_get_const_data (filename), error.message); dbus_error_free (&error); goto out; } @@ -335,7 +333,7 @@ _dbus_auth_script_run (const DBusString *filename) _dbus_string_delete_first_word (&line); - if (!_dbus_string_init (&to_send, _DBUS_INT_MAX)) + if (!_dbus_string_init (&to_send)) { _dbus_warn ("no memory to allocate string\n"); goto out; @@ -349,11 +347,7 @@ _dbus_auth_script_run (const DBusString *filename) goto out; } - { - const char *s4; - _dbus_string_get_const_data (&to_send, &s4); - _dbus_verbose ("Sending '%s'\n", s4); - } + _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send)); if (!_dbus_string_append (&to_send, "\r\n")) { @@ -372,7 +366,7 @@ _dbus_auth_script_run (const DBusString *filename) { DBusString username; - if (!_dbus_string_init (&username, _DBUS_INT_MAX)) + if (!_dbus_string_init (&username)) { _dbus_warn ("no memory for userid\n"); _dbus_string_free (&to_send); @@ -406,7 +400,7 @@ _dbus_auth_script_run (const DBusString *filename) DBusString username; const DBusString *u; - if (!_dbus_string_init (&username, _DBUS_INT_MAX)) + if (!_dbus_string_init (&username)) { _dbus_warn ("no memory for username\n"); _dbus_string_free (&to_send); @@ -486,7 +480,7 @@ _dbus_auth_script_run (const DBusString *filename) _dbus_string_delete_first_word (&line); - if (!_dbus_string_init (&received, _DBUS_INT_MAX)) + if (!_dbus_string_init (&received)) { _dbus_warn ("no mem to allocate string received\n"); goto out; @@ -494,21 +488,18 @@ _dbus_auth_script_run (const DBusString *filename) if (!_dbus_string_pop_line (&from_auth, &received)) { - const char *command; - _dbus_string_get_const_data (&line, &command); _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d\n", - command, line_no); + _dbus_string_get_const_data (&line), line_no); _dbus_string_free (&received); goto out; } if (!same_first_word (&received, &line)) { - const char *s1, *s2; - _dbus_string_get_const_data (&line, &s1); - _dbus_string_get_const_data (&received, &s2); _dbus_warn ("line %d expected command '%s' and got '%s'\n", - line_no, s1, s2); + line_no, + _dbus_string_get_const_data (&line), + _dbus_string_get_const_data (&received)); _dbus_string_free (&received); goto out; } @@ -523,7 +514,7 @@ _dbus_auth_script_run (const DBusString *filename) _dbus_string_delete_first_word (&line); - if (!_dbus_string_init (&expected, _DBUS_INT_MAX)) + if (!_dbus_string_init (&expected)) { _dbus_warn ("no mem to allocate string expected\n"); goto out; @@ -546,11 +537,9 @@ _dbus_auth_script_run (const DBusString *filename) } else { - const char *e1, *h1; - _dbus_string_get_const_data (&expected, &e1); - _dbus_string_get_const_data (unused, &h1); _dbus_warn ("Expected unused bytes '%s' and have '%s'\n", - e1, h1); + _dbus_string_get_const_data (&expected), + _dbus_string_get_const_data (unused)); _dbus_string_free (&expected); goto out; } @@ -562,7 +551,7 @@ _dbus_auth_script_run (const DBusString *filename) _dbus_string_delete_first_word (&line); - if (!_dbus_string_init (&expected, _DBUS_INT_MAX)) + if (!_dbus_string_init (&expected)) { _dbus_warn ("no mem to allocate string expected\n"); goto out; @@ -585,11 +574,9 @@ _dbus_auth_script_run (const DBusString *filename) } else { - const char *e1, *h1; - _dbus_string_get_const_data (&expected, &e1); - _dbus_string_get_const_data (&from_auth, &h1); _dbus_warn ("Expected exact string '%s' and have '%s'\n", - e1, h1); + _dbus_string_get_const_data (&expected), + _dbus_string_get_const_data (&from_auth)); _dbus_string_free (&expected); goto out; } @@ -601,10 +588,8 @@ _dbus_auth_script_run (const DBusString *filename) parse_failed: { - const char *s; - _dbus_string_get_const_data (&line, &s); _dbus_warn ("couldn't process line %d \"%s\"\n", - line_no, s); + line_no, _dbus_string_get_const_data (&line)); goto out; } } @@ -618,10 +603,8 @@ _dbus_auth_script_run (const DBusString *filename) if (_dbus_string_get_length (&from_auth) > 0) { - const char *s; _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth\n"); - _dbus_string_get_const_data (&from_auth, &s); - _dbus_warn ("Leftover data: %s\n", s); + _dbus_warn ("Leftover data: %s\n", _dbus_string_get_const_data (&from_auth)); goto out; } diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c index 1aa83e7c..fd4f60dc 100644 --- a/dbus/dbus-auth.c +++ b/dbus/dbus-auth.c @@ -295,19 +295,19 @@ _dbus_auth_new (int size) * overlong buffers in _dbus_auth_do_work(). */ - if (!_dbus_string_init (&auth->incoming, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth->incoming)) goto enomem_0; - if (!_dbus_string_init (&auth->outgoing, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth->outgoing)) goto enomem_1; - if (!_dbus_string_init (&auth->identity, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth->identity)) goto enomem_2; - if (!_dbus_string_init (&auth->context, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth->context)) goto enomem_3; - if (!_dbus_string_init (&auth->challenge, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth->challenge)) goto enomem_4; /* default context if none is specified */ @@ -381,7 +381,7 @@ sha1_compute_hash (DBusAuth *auth, retval = FALSE; - if (!_dbus_string_init (&cookie, _DBUS_INT_MAX)) + if (!_dbus_string_init (&cookie)) return FALSE; if (!_dbus_keyring_get_hex_key (auth->keyring, cookie_id, @@ -394,7 +394,7 @@ sha1_compute_hash (DBusAuth *auth, goto out_0; } - if (!_dbus_string_init (&to_hash, _DBUS_INT_MAX)) + if (!_dbus_string_init (&to_hash)) goto out_0; if (!_dbus_string_copy (server_challenge, 0, @@ -474,10 +474,10 @@ sha1_handle_first_client_response (DBusAuth *auth, return send_rejected (auth); } - if (!_dbus_string_init (&tmp, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tmp)) return FALSE; - if (!_dbus_string_init (&tmp2, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tmp2)) { _dbus_string_free (&tmp); return FALSE; @@ -621,10 +621,10 @@ sha1_handle_second_client_response (DBusAuth *auth, return send_rejected (auth); } - if (!_dbus_string_init (&client_challenge, _DBUS_INT_MAX)) + if (!_dbus_string_init (&client_challenge)) goto out_0; - if (!_dbus_string_init (&client_hash, _DBUS_INT_MAX)) + if (!_dbus_string_init (&client_hash)) goto out_1; if (!_dbus_string_copy_len (data, 0, i, &client_challenge, @@ -648,7 +648,7 @@ sha1_handle_second_client_response (DBusAuth *auth, goto out_2; } - if (!_dbus_string_init (&correct_hash, _DBUS_INT_MAX)) + if (!_dbus_string_init (&correct_hash)) goto out_2; if (!sha1_compute_hash (auth, auth->cookie_id, @@ -769,7 +769,7 @@ handle_client_data_cookie_sha1_mech (DBusAuth *auth, goto out_0; } - if (!_dbus_string_init (&context, _DBUS_INT_MAX)) + if (!_dbus_string_init (&context)) goto out_0; if (!_dbus_string_copy_len (data, 0, i, @@ -785,14 +785,14 @@ handle_client_data_cookie_sha1_mech (DBusAuth *auth, goto out_1; } - if (!_dbus_string_init (&cookie_id_str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&cookie_id_str)) goto out_1; if (!_dbus_string_copy_len (data, i, j - i, &cookie_id_str, 0)) goto out_2; - if (!_dbus_string_init (&server_challenge, _DBUS_INT_MAX)) + if (!_dbus_string_init (&server_challenge)) goto out_2; i = j; @@ -867,19 +867,19 @@ handle_client_data_cookie_sha1_mech (DBusAuth *auth, _dbus_assert (auth->keyring != NULL); - if (!_dbus_string_init (&tmp, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tmp)) goto out_3; if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES)) goto out_4; - if (!_dbus_string_init (&client_challenge, _DBUS_INT_MAX)) + if (!_dbus_string_init (&client_challenge)) goto out_4; if (!_dbus_string_hex_encode (&tmp, 0, &client_challenge, 0)) goto out_5; - if (!_dbus_string_init (&correct_hash, _DBUS_INT_MAX)) + if (!_dbus_string_init (&correct_hash)) goto out_6; if (!sha1_compute_hash (auth, val, @@ -1069,7 +1069,7 @@ handle_client_initial_response_external_mech (DBusAuth *auth, */ DBusString plaintext; - if (!_dbus_string_init (&plaintext, _DBUS_INT_MAX)) + if (!_dbus_string_init (&plaintext)) return FALSE; if (!_dbus_string_append_our_uid (&plaintext)) @@ -1159,7 +1159,7 @@ send_rejected (DBusAuth *auth) DBusAuthServer *server_auth; int i; - if (!_dbus_string_init (&command, _DBUS_INT_MAX)) + if (!_dbus_string_init (&command)) return FALSE; if (!_dbus_string_append (&command, @@ -1233,16 +1233,16 @@ process_auth (DBusAuth *auth, _dbus_string_find_blank (args, 0, &i); - if (!_dbus_string_init (&mech, _DBUS_INT_MAX)) + if (!_dbus_string_init (&mech)) return FALSE; - if (!_dbus_string_init (&base64_response, _DBUS_INT_MAX)) + if (!_dbus_string_init (&base64_response)) { _dbus_string_free (&mech); return FALSE; } - if (!_dbus_string_init (&decoded_response, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded_response)) { _dbus_string_free (&mech); _dbus_string_free (&base64_response); @@ -1329,7 +1329,7 @@ process_data_server (DBusAuth *auth, { DBusString decoded; - if (!_dbus_string_init (&decoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded)) return FALSE; if (!_dbus_string_base64_decode (args, 0, &decoded, 0)) @@ -1341,11 +1341,7 @@ process_data_server (DBusAuth *auth, #ifdef DBUS_ENABLE_VERBOSE_MODE if (_dbus_string_validate_ascii (&decoded, 0, _dbus_string_get_length (&decoded))) - { - const char *s; - _dbus_string_get_const_data (&decoded, &s); - _dbus_verbose ("data: '%s'\n", s); - } + _dbus_verbose ("data: '%s'\n", _dbus_string_get_const_data (&decoded)); #endif if (!(* auth->mech->server_data_func) (auth, &decoded)) @@ -1416,7 +1412,7 @@ record_mechanisms (DBusAuth *auth, DBusString m; const DBusAuthMechanismHandler *mech; - if (!_dbus_string_init (&m, _DBUS_INT_MAX)) + if (!_dbus_string_init (&m)) goto nomem; if (!get_word (args, &next, &m)) @@ -1444,11 +1440,8 @@ record_mechanisms (DBusAuth *auth, } else { - const char *s; - - _dbus_string_get_const_data (&m, &s); _dbus_verbose ("Server offered mechanism \"%s\" that we don't know how to use\n", - s); + _dbus_string_get_const_data (&m)); } _dbus_string_free (&m); @@ -1475,7 +1468,7 @@ client_try_next_mechanism (DBusAuth *auth) mech = DBUS_AUTH_CLIENT (auth)->mechs_to_try->data; - if (!_dbus_string_init (&auth_command, _DBUS_INT_MAX)) + if (!_dbus_string_init (&auth_command)) return FALSE; if (!_dbus_string_append (&auth_command, @@ -1582,7 +1575,7 @@ process_data_client (DBusAuth *auth, { DBusString decoded; - if (!_dbus_string_init (&decoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded)) return FALSE; if (!_dbus_string_base64_decode (args, 0, &decoded, 0)) @@ -1595,9 +1588,8 @@ process_data_client (DBusAuth *auth, if (_dbus_string_validate_ascii (&decoded, 0, _dbus_string_get_length (&decoded))) { - const char *s; - _dbus_string_get_const_data (&decoded, &s); - _dbus_verbose ("data: '%s'\n", s); + _dbus_verbose ("data: '%s'\n", + _dbus_string_get_const_data (&decoded)); } #endif @@ -1657,13 +1649,13 @@ process_command (DBusAuth *auth) if (!_dbus_string_find (&auth->incoming, 0, "\r\n", &eol)) return FALSE; - if (!_dbus_string_init (&command, _DBUS_INT_MAX)) + if (!_dbus_string_init (&command)) { auth->needed_memory = TRUE; return FALSE; } - if (!_dbus_string_init (&args, _DBUS_INT_MAX)) + if (!_dbus_string_init (&args)) { _dbus_string_free (&command); auth->needed_memory = TRUE; @@ -1692,11 +1684,7 @@ process_command (DBusAuth *auth) goto next_command; } - { - const char *q; - _dbus_string_get_const_data (&command, &q); - _dbus_verbose ("got command \"%s\"\n", q); - } + _dbus_verbose ("got command \"%s\"\n", _dbus_string_get_const_data (&command)); _dbus_string_find_blank (&command, 0, &i); _dbus_string_skip_blank (&command, i, &j); @@ -1983,11 +1971,8 @@ void _dbus_auth_bytes_sent (DBusAuth *auth, int bytes_sent) { - { - const char *s; - _dbus_string_get_const_data (&auth->outgoing, &s); - _dbus_verbose ("Sent %d bytes of: %s\n", bytes_sent, s); - } + _dbus_verbose ("Sent %d bytes of: %s\n", bytes_sent, + _dbus_string_get_const_data (&auth->outgoing)); _dbus_string_delete (&auth->outgoing, 0, bytes_sent); @@ -2264,7 +2249,7 @@ process_test_subdir (const DBusString *test_base_dir, retval = FALSE; dir = NULL; - if (!_dbus_string_init (&test_directory, _DBUS_INT_MAX)) + if (!_dbus_string_init (&test_directory)) _dbus_assert_not_reached ("didn't allocate test_directory\n"); _dbus_string_init_const (&filename, subdir); @@ -2277,16 +2262,15 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_assert_not_reached ("couldn't allocate full path"); _dbus_string_free (&filename); - if (!_dbus_string_init (&filename, _DBUS_INT_MAX)) + 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) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); - _dbus_warn ("Could not open %s: %s\n", s, + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), error.message); dbus_error_free (&error); goto failed; @@ -2299,7 +2283,7 @@ process_test_subdir (const DBusString *test_base_dir, { DBusString full_path; - if (!_dbus_string_init (&full_path, _DBUS_INT_MAX)) + if (!_dbus_string_init (&full_path)) _dbus_assert_not_reached ("couldn't init string"); if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) @@ -2310,19 +2294,13 @@ process_test_subdir (const DBusString *test_base_dir, if (!_dbus_string_ends_with_c_str (&filename, ".auth-script")) { - const char *filename_c; - _dbus_string_get_const_data (&filename, &filename_c); _dbus_verbose ("Skipping non-.auth-script file %s\n", - filename_c); + _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); goto next; } - { - const char *s; - _dbus_string_get_const_data (&filename, &s); - printf (" %s\n", s); - } + printf (" %s\n", _dbus_string_get_const_data (&filename)); if (!_dbus_auth_script_run (&full_path)) { @@ -2335,10 +2313,8 @@ process_test_subdir (const DBusString *test_base_dir, if (dbus_error_is_set (&error)) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); _dbus_warn ("Could not get next file in %s: %s\n", - s, error.message); + _dbus_string_get_const_data (&test_directory), error.message); dbus_error_free (&error); goto failed; } diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c index c5760a1d..fbaf7cd2 100644 --- a/dbus/dbus-keyring.c +++ b/dbus/dbus-keyring.c @@ -109,16 +109,16 @@ _dbus_keyring_new (void) if (keyring == NULL) goto out_0; - if (!_dbus_string_init (&keyring->directory, _DBUS_INT_MAX)) + if (!_dbus_string_init (&keyring->directory)) goto out_1; - if (!_dbus_string_init (&keyring->filename, _DBUS_INT_MAX)) + if (!_dbus_string_init (&keyring->filename)) goto out_2; - if (!_dbus_string_init (&keyring->filename_lock, _DBUS_INT_MAX)) + if (!_dbus_string_init (&keyring->filename_lock)) goto out_3; - if (!_dbus_string_init (&keyring->username, _DBUS_INT_MAX)) + if (!_dbus_string_init (&keyring->username)) goto out_4; keyring->refcount = 1; @@ -280,7 +280,7 @@ add_new_key (DBusKey **keys_p, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&bytes, _DBUS_INT_MAX)) + if (!_dbus_string_init (&bytes)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return FALSE; @@ -299,7 +299,7 @@ add_new_key (DBusKey **keys_p, goto out; } - _dbus_string_get_const_data (&bytes, (const char**) &s); + s = (const unsigned char*) _dbus_string_get_const_data (&bytes); id = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); if (id < 0) @@ -334,8 +334,7 @@ add_new_key (DBusKey **keys_p, keys = new; n_keys += 1; - if (!_dbus_string_init (&keys[n_keys-1].secret, - _DBUS_INT_MAX)) + if (!_dbus_string_init (&keys[n_keys-1].secret)) { n_keys -= 1; /* we don't want to free the one we didn't init */ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); @@ -398,13 +397,13 @@ _dbus_keyring_reload (DBusKeyring *keyring, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&contents, _DBUS_INT_MAX)) + if (!_dbus_string_init (&contents)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return FALSE; } - if (!_dbus_string_init (&line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&line)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); _dbus_string_free (&contents); @@ -510,8 +509,7 @@ _dbus_keyring_reload (DBusKeyring *keyring, keys = new; n_keys += 1; - if (!_dbus_string_init (&keys[n_keys-1].secret, - _DBUS_INT_MAX)) + if (!_dbus_string_init (&keys[n_keys-1].secret)) { n_keys -= 1; /* we don't want to free the one we didn't init */ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); @@ -689,7 +687,7 @@ _dbus_keyring_new_homedir (const DBusString *username, keyring = NULL; error_set = FALSE; - if (!_dbus_string_init (&homedir, _DBUS_INT_MAX)) + if (!_dbus_string_init (&homedir)) return FALSE; _dbus_string_init_const (&dotdir, ".dbus-keyrings"); @@ -1022,7 +1020,7 @@ _dbus_keyring_test (void) _dbus_string_init_const (&context, "foo bar"); _dbus_assert (!_dbus_keyring_validate_context (&context)); - if (!_dbus_string_init (&context, _DBUS_INT_MAX)) + if (!_dbus_string_init (&context)) _dbus_assert_not_reached ("no memory"); if (!_dbus_string_append_byte (&context, '\0')) _dbus_assert_not_reached ("no memory"); diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 51c4ce10..2222ad9b 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -157,7 +157,7 @@ _dbus_marshal_set_int32 (DBusString *str, _dbus_assert (byte_order == DBUS_LITTLE_ENDIAN || byte_order == DBUS_BIG_ENDIAN); - _dbus_string_get_data_len (str, &data, offset, 4); + data = _dbus_string_get_data_len (str, offset, 4); _dbus_pack_int32 (value, byte_order, data); } @@ -183,7 +183,7 @@ _dbus_marshal_set_uint32 (DBusString *str, _dbus_assert (byte_order == DBUS_LITTLE_ENDIAN || byte_order == DBUS_BIG_ENDIAN); - _dbus_string_get_data_len (str, &data, offset, 4); + data = _dbus_string_get_data_len (str, offset, 4); _dbus_pack_uint32 (value, byte_order, data); } @@ -705,7 +705,7 @@ _dbus_demarshal_double (const DBusString *str, pos = _DBUS_ALIGN_VALUE (pos, sizeof (double)); - _dbus_string_get_const_data_len (str, &buffer, pos, sizeof (double)); + buffer = _dbus_string_get_const_data_len (str, pos, sizeof (double)); retval = *(double *)buffer; @@ -807,7 +807,7 @@ _dbus_demarshal_string (const DBusString *str, if (!retval) return NULL; - _dbus_string_get_const_data_len (str, &data, pos, len); + data = _dbus_string_get_const_data_len (str, pos, len); if (!data) return NULL; @@ -865,7 +865,7 @@ _dbus_demarshal_byte_array (const DBusString *str, if (!retval) return FALSE; - _dbus_string_get_const_data_len (str, &data, pos, len); + data = _dbus_string_get_const_data_len (str, pos, len); if (!data) { @@ -1342,7 +1342,7 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, if (pos >= _dbus_string_get_length (str)) return FALSE; - _dbus_string_get_const_data_len (str, &data, pos, 1); + data = _dbus_string_get_const_data_len (str, pos, 1); switch (*data) { @@ -1602,7 +1602,7 @@ _dbus_marshal_validate_arg (const DBusString *str, if (pos >= _dbus_string_get_length (str)) return FALSE; - _dbus_string_get_const_data_len (str, &data, pos, 1); + data = _dbus_string_get_const_data_len (str, pos, 1); switch (*data) { @@ -1957,8 +1957,7 @@ _dbus_verbose_bytes_of_string (const DBusString *str, len = real_len - start; } - - _dbus_string_get_const_data_len (str, &d, start, len); + d = _dbus_string_get_const_data_len (str, start, len); _dbus_verbose_bytes (d, len); } @@ -1993,7 +1992,7 @@ _dbus_marshal_test (void) const char **our_string_array; DBusDict *dict; - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); /* Marshal doubles */ diff --git a/dbus/dbus-md5.c b/dbus/dbus-md5.c index 82003c0d..9f025c51 100644 --- a/dbus/dbus-md5.c +++ b/dbus/dbus-md5.c @@ -475,7 +475,7 @@ _dbus_md5_compute (const DBusString *data, _dbus_md5_update (&context, data); - if (!_dbus_string_init (&digest, _DBUS_INT_MAX)) + if (!_dbus_string_init (&digest)) return FALSE; if (!_dbus_md5_final (&context, &digest)) @@ -512,7 +512,7 @@ check_md5_binary (const unsigned char *input, _dbus_string_init_const_len (&input_str, input, input_len); _dbus_string_init_const (&expected_str, expected); - if (!_dbus_string_init (&results, _DBUS_INT_MAX)) + if (!_dbus_string_init (&results)) _dbus_assert_not_reached ("no memory for md5 results"); if (!_dbus_md5_compute (&input_str, &results)) diff --git a/dbus/dbus-message-builder.c b/dbus/dbus-message-builder.c index e34e1b55..044c2a7b 100644 --- a/dbus/dbus-message-builder.c +++ b/dbus/dbus-message-builder.c @@ -67,8 +67,8 @@ ensure_saved_length (DBusHashTable *hash, { SavedLength *sl; const char *s; - - _dbus_string_get_const_data (name, &s); + + s = _dbus_string_get_const_data (name); sl = _dbus_hash_table_lookup_string (hash, s); if (sl != NULL) @@ -76,7 +76,7 @@ ensure_saved_length (DBusHashTable *hash, sl = dbus_new0 (SavedLength, 1); - if (!_dbus_string_init (&sl->name, _DBUS_INT_MAX)) + if (!_dbus_string_init (&sl->name)) { dbus_free (sl); return NULL; @@ -85,7 +85,7 @@ ensure_saved_length (DBusHashTable *hash, if (!_dbus_string_copy (name, 0, &sl->name, 0)) goto failed; - _dbus_string_get_const_data (&sl->name, &s); + s = _dbus_string_get_const_data (&sl->name); if (!_dbus_hash_table_insert_string (hash, (char*)s, sl)) goto failed; @@ -326,28 +326,22 @@ _dbus_message_data_load (DBusString *dest, retval = FALSE; length_hash = NULL; - if (!_dbus_string_init (&file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&file)) return FALSE; - if (!_dbus_string_init (&line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&line)) { _dbus_string_free (&file); return FALSE; } - { - const char *s; - _dbus_string_get_const_data (filename, &s); - _dbus_verbose ("Loading %s\n", s); - } + _dbus_verbose ("Loading %s\n", _dbus_string_get_const_data (filename)); dbus_error_init (&error); if (!_dbus_file_get_contents (&file, filename, &error)) { - const char *s; - _dbus_string_get_const_data (filename, &s); _dbus_warn ("Getting contents of %s failed: %s\n", - s, error.message); + _dbus_string_get_const_data (filename), error.message); dbus_error_free (&error); goto out; } @@ -600,10 +594,8 @@ _dbus_message_data_load (DBusString *dest, if (_dbus_string_get_length (&line) != 4) { - const char *s; - _dbus_string_get_const_data (&line, &s); _dbus_warn ("Field name must be four characters not \"%s\"\n", - s); + _dbus_string_get_const_data (&line)); goto parse_failed; } @@ -653,9 +645,7 @@ _dbus_message_data_load (DBusString *dest, code = DBUS_TYPE_DICT; else { - const char *s; - _dbus_string_get_const_data (&line, &s); - _dbus_warn ("%s is not a valid type name\n", s); + _dbus_warn ("%s is not a valid type name\n", _dbus_string_get_const_data (&line)); goto parse_failed; } @@ -972,7 +962,7 @@ _dbus_message_data_load (DBusString *dest, if (b != '{') goto parse_failed; - _dbus_string_init (&val_str, _DBUS_INT_MAX); + _dbus_string_init (&val_str); while (i < _dbus_string_get_length (&line)) { _dbus_string_skip_blank (&line, i, &i); @@ -1157,10 +1147,8 @@ _dbus_message_data_load (DBusString *dest, parse_failed: { - const char *s; - _dbus_string_get_const_data (&line, &s); _dbus_warn ("couldn't process line %d \"%s\"\n", - line_no, s); + line_no, _dbus_string_get_const_data (&line)); goto out; } } @@ -1171,7 +1159,7 @@ _dbus_message_data_load (DBusString *dest, SavedLength *sl = _dbus_hash_iter_get_value (&iter); const char *s; - _dbus_string_get_const_data (&sl->name, &s); + s = _dbus_string_get_const_data (&sl->name); if (sl->length < 0) { diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 524a7a3f..39ed3942 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -209,8 +209,7 @@ get_string_field (DBusMessage *message, offset, NULL); - _dbus_string_get_const_data (&message->header, - &data); + data = _dbus_string_get_const_data (&message->header); return data + (offset + 4); } @@ -759,13 +758,13 @@ dbus_message_new_empty_header (void) ++i; } - if (!_dbus_string_init (&message->header, _DBUS_INT_MAX)) + if (!_dbus_string_init (&message->header)) { dbus_free (message); return NULL; } - if (!_dbus_string_init (&message->body, _DBUS_INT_MAX)) + if (!_dbus_string_init (&message->body)) { _dbus_string_free (&message->header); dbus_free (message); @@ -915,13 +914,13 @@ dbus_message_copy (const DBusMessage *message) retval->header_padding = message->header_padding; retval->locked = FALSE; - if (!_dbus_string_init (&retval->header, _DBUS_INT_MAX)) + if (!_dbus_string_init (&retval->header)) { dbus_free (retval); return NULL; } - if (!_dbus_string_init (&retval->body, _DBUS_INT_MAX)) + if (!_dbus_string_init (&retval->body)) { _dbus_string_free (&retval->header); dbus_free (retval); @@ -1949,7 +1948,7 @@ dbus_message_iter_get_arg_type (DBusMessageIter *iter) if (iter->pos >= _dbus_string_get_length (&iter->message->body)) return DBUS_TYPE_INVALID; - _dbus_string_get_const_data_len (&iter->message->body, &data, iter->pos, 1); + data = _dbus_string_get_const_data_len (&iter->message->body, iter->pos, 1); if (*data > DBUS_TYPE_INVALID && *data <= DBUS_TYPE_DICT) return *data; @@ -2262,7 +2261,7 @@ dbus_message_set_is_error (DBusMessage *message, _dbus_assert (!message->locked); - _dbus_string_get_data_len (&message->header, &header, 1, 1); + header = _dbus_string_get_data_len (&message->header, 1, 1); if (is_error_reply) *header |= DBUS_HEADER_FLAG_ERROR; @@ -2282,7 +2281,7 @@ dbus_message_get_is_error (DBusMessage *message) { const char *header; - _dbus_string_get_const_data_len (&message->header, &header, 1, 1); + header = _dbus_string_get_const_data_len (&message->header, 1, 1); return (*header & DBUS_HEADER_FLAG_ERROR) != 0; } @@ -2469,7 +2468,7 @@ _dbus_message_loader_new (void) */ loader->max_message_size = _DBUS_ONE_MEGABYTE * 32; - if (!_dbus_string_init (&loader->data, _DBUS_INT_MAX)) + if (!_dbus_string_init (&loader->data)) { dbus_free (loader); return NULL; @@ -2612,7 +2611,7 @@ decode_header_data (const DBusString *data, if ((pos + 4) > header_len) return FALSE; - _dbus_string_get_const_data_len (data, &field, pos, 4); + field =_dbus_string_get_const_data_len (data, pos, 4); pos += 4; _dbus_assert (_DBUS_ALIGN_ADDRESS (field, 4) == field); @@ -2766,7 +2765,7 @@ _dbus_message_loader_queue_messages (DBusMessageLoader *loader) int byte_order, header_len, body_len, header_padding; dbus_uint32_t header_len_unsigned, body_len_unsigned; - _dbus_string_get_const_data_len (&loader->data, &header_data, 0, 16); + header_data = _dbus_string_get_const_data_len (&loader->data, 0, 16); _dbus_assert (_DBUS_ALIGN_ADDRESS (header_data, 4) == header_data); @@ -3373,9 +3372,9 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename, dbus_error_init (&error); if (!_dbus_file_get_contents (data, filename, &error)) { - const char *s; - _dbus_string_get_const_data (filename, &s); - _dbus_warn ("Could not load message file %s: %s\n", s, error.message); + _dbus_warn ("Could not load message file %s: %s\n", + _dbus_string_get_const_data (filename), + error.message); dbus_error_free (&error); goto failed; } @@ -3384,9 +3383,8 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename, { if (!_dbus_message_data_load (data, filename)) { - const char *s; - _dbus_string_get_const_data (filename, &s); - _dbus_warn ("Could not load message file %s\n", s); + _dbus_warn ("Could not load message file %s\n", + _dbus_string_get_const_data (filename)); goto failed; } } @@ -3417,7 +3415,7 @@ dbus_internal_do_not_use_try_message_file (const DBusString *filename, retval = FALSE; - if (!_dbus_string_init (&data, _DBUS_INT_MAX)) + if (!_dbus_string_init (&data)) _dbus_assert_not_reached ("could not allocate string\n"); if (!dbus_internal_do_not_use_load_message_file (filename, is_raw, @@ -3430,15 +3428,12 @@ dbus_internal_do_not_use_try_message_file (const DBusString *filename, if (!retval) { - const char *s; - if (_dbus_string_get_length (&data) > 0) _dbus_verbose_bytes_of_string (&data, 0, _dbus_string_get_length (&data)); - _dbus_string_get_const_data (filename, &s); _dbus_warn ("Failed message loader test on %s\n", - s); + _dbus_string_get_const_data (filename)); } _dbus_string_free (&data); @@ -3556,7 +3551,7 @@ process_test_subdir (const DBusString *test_base_dir, retval = FALSE; dir = NULL; - if (!_dbus_string_init (&test_directory, _DBUS_INT_MAX)) + if (!_dbus_string_init (&test_directory)) _dbus_assert_not_reached ("didn't allocate test_directory\n"); _dbus_string_init_const (&filename, subdir); @@ -3569,16 +3564,15 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_assert_not_reached ("couldn't allocate full path"); _dbus_string_free (&filename); - if (!_dbus_string_init (&filename, _DBUS_INT_MAX)) + 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) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); - _dbus_warn ("Could not open %s: %s\n", s, + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), error.message); dbus_error_free (&error); goto failed; @@ -3592,7 +3586,7 @@ process_test_subdir (const DBusString *test_base_dir, DBusString full_path; dbus_bool_t is_raw; - if (!_dbus_string_init (&full_path, _DBUS_INT_MAX)) + if (!_dbus_string_init (&full_path)) _dbus_assert_not_reached ("couldn't init string"); if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) @@ -3607,19 +3601,14 @@ process_test_subdir (const DBusString *test_base_dir, is_raw = TRUE; else { - const char *filename_c; - _dbus_string_get_const_data (&filename, &filename_c); _dbus_verbose ("Skipping non-.message file %s\n", - filename_c); + _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); goto next; } - { - const char *s; - _dbus_string_get_const_data (&filename, &s); - printf (" %s\n", s); - } + printf (" %s\n", + _dbus_string_get_const_data (&filename)); _dbus_verbose (" expecting %s\n", validity == _DBUS_MESSAGE_VALID ? "valid" : @@ -3637,10 +3626,9 @@ process_test_subdir (const DBusString *test_base_dir, if (dbus_error_is_set (&error)) { - const char *s; - _dbus_string_get_const_data (&test_directory, &s); _dbus_warn ("Could not get next file in %s: %s\n", - s, error.message); + _dbus_string_get_const_data (&test_directory), + error.message); dbus_error_free (&error); goto failed; } @@ -3801,7 +3789,7 @@ _dbus_message_test (const char *test_data_dir) loader = _dbus_message_loader_new (); /* Write the header data one byte at a time */ - _dbus_string_get_const_data (&message->header, &data); + data = _dbus_string_get_const_data (&message->header); for (i = 0; i < _dbus_string_get_length (&message->header); i++) { DBusString *buffer; @@ -3812,7 +3800,7 @@ _dbus_message_test (const char *test_data_dir) } /* Write the body data one byte at a time */ - _dbus_string_get_const_data (&message->body, &data); + data = _dbus_string_get_const_data (&message->body); for (i = 0; i < _dbus_string_get_length (&message->body); i++) { DBusString *buffer; diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c index ed65298b..76f734b4 100644 --- a/dbus/dbus-server-debug-pipe.c +++ b/dbus/dbus-server-debug-pipe.c @@ -159,7 +159,7 @@ _dbus_server_debug_pipe_new (const char *server_name, if (debug_server == NULL) goto nomem_0; - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) goto nomem_1; if (!_dbus_string_append (&address, "debug-pipe:name=") || @@ -230,7 +230,7 @@ _dbus_transport_debug_pipe_new (const char *server_name, return NULL; } - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; diff --git a/dbus/dbus-server-debug.c b/dbus/dbus-server-debug.c index e61f8099..513e1df2 100644 --- a/dbus/dbus-server-debug.c +++ b/dbus/dbus-server-debug.c @@ -144,7 +144,7 @@ _dbus_server_debug_new (const char *server_name, if (debug_server == NULL) return NULL; - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) goto nomem_0; if (!_dbus_string_append (&address, "debug:name=") || diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index ee26b243..e5e6d70e 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -265,7 +265,7 @@ _dbus_server_new_for_domain_socket (const char *path, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; @@ -322,7 +322,7 @@ _dbus_server_new_for_tcp_socket (const char *host, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c index 8f047122..a0918d69 100644 --- a/dbus/dbus-sha.c +++ b/dbus/dbus-sha.c @@ -432,9 +432,9 @@ _dbus_sha_update (DBusSHAContext *context, const DBusString *data) { unsigned int inputLen; - unsigned char *input; + const unsigned char *input; - _dbus_string_get_const_data (data, (const char**) &input); + input = (const unsigned char*) _dbus_string_get_const_data (data); inputLen = _dbus_string_get_length (data); sha_append (context, input, inputLen); @@ -489,7 +489,7 @@ _dbus_sha_compute (const DBusString *data, _dbus_sha_update (&context, data); - if (!_dbus_string_init (&digest, _DBUS_INT_MAX)) + if (!_dbus_string_init (&digest)) return FALSE; if (!_dbus_sha_final (&context, &digest)) @@ -526,7 +526,7 @@ check_sha_binary (const unsigned char *input, _dbus_string_init_const_len (&input_str, input, input_len); _dbus_string_init_const (&expected_str, expected); - if (!_dbus_string_init (&results, _DBUS_INT_MAX)) + if (!_dbus_string_init (&results)) _dbus_assert_not_reached ("no memory for SHA-1 results"); if (!_dbus_sha_compute (&input_str, &results)) @@ -534,10 +534,9 @@ check_sha_binary (const unsigned char *input, if (!_dbus_string_equal (&expected_str, &results)) { - const char *s; - _dbus_string_get_const_data (&results, &s); _dbus_warn ("Expected hash %s got %s for SHA-1 sum\n", - expected, s); + expected, + _dbus_string_get_const_data (&results)); _dbus_string_free (&results); return FALSE; } @@ -569,10 +568,8 @@ decode_compact_string (const DBusString *line, if (!_dbus_string_parse_int (line, offset, &val, &next)) { - const char *s; - _dbus_string_get_const_data (line, &s); fprintf (stderr, "could not parse length at start of compact string: %s\n", - s); + _dbus_string_get_const_data (line)); return FALSE; } @@ -581,10 +578,8 @@ decode_compact_string (const DBusString *line, offset = next; if (!_dbus_string_parse_int (line, offset, &val, &next)) { - const char *s; - _dbus_string_get_const_data (line, &s); fprintf (stderr, "could not parse start bit 'b' in compact string: %s\n", - s); + _dbus_string_get_const_data (line)); return FALSE; } @@ -668,7 +663,7 @@ get_next_expected_result (DBusString *results, retval = FALSE; - if (!_dbus_string_init (&line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&line)) _dbus_assert_not_reached ("no memory"); next_iteration: @@ -682,8 +677,6 @@ get_next_expected_result (DBusString *results, goto next_iteration; else if (_dbus_string_starts_with_c_str (&line, "H>")) { - const char *s; - _dbus_string_get_const_data (&line, &s); /* don't print */ } else if (_dbus_string_starts_with_c_str (&line, "D>") || @@ -756,19 +749,19 @@ process_test_data (const char *test_data_dir) retval = FALSE; - if (!_dbus_string_init (&tests_file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tests_file)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&results_file, _DBUS_INT_MAX)) + if (!_dbus_string_init (&results_file)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&tests, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tests)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&results, _DBUS_INT_MAX)) + if (!_dbus_string_init (&results)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&line)) _dbus_assert_not_reached ("no memory"); if (!_dbus_string_append (&tests_file, test_data_dir)) @@ -788,20 +781,17 @@ process_test_data (const char *test_data_dir) dbus_error_init (&error); if (!_dbus_file_get_contents (&tests, &tests_file, &error)) { - const char *s; - _dbus_string_get_const_data (&tests_file, &s); fprintf (stderr, "could not load test data file %s: %s\n", - s, error.message); + _dbus_string_get_const_data (&tests_file), + error.message); dbus_error_free (&error); goto out; } if (!_dbus_file_get_contents (&results, &results_file, &error)) { - const char *s; - _dbus_string_get_const_data (&results_file, &s); fprintf (stderr, "could not load results data file %s: %s\n", - s, error.message); + _dbus_string_get_const_data (&results_file), error.message); dbus_error_free (&error); goto out; } @@ -821,9 +811,7 @@ process_test_data (const char *test_data_dir) goto next_iteration; else if (_dbus_string_starts_with_c_str (&line, "H>")) { - const char *s; - _dbus_string_get_const_data (&line, &s); - printf ("SHA-1: %s\n", s); + printf ("SHA-1: %s\n", _dbus_string_get_const_data (&line)); if (_dbus_string_find (&line, 0, "Type 3", NULL)) { @@ -850,16 +838,16 @@ process_test_data (const char *test_data_dir) success = FALSE; - if (!_dbus_string_init (&next_line, _DBUS_INT_MAX)) + if (!_dbus_string_init (&next_line)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&expected, _DBUS_INT_MAX)) + if (!_dbus_string_init (&expected)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&test, _DBUS_INT_MAX)) + if (!_dbus_string_init (&test)) _dbus_assert_not_reached ("no memory"); - if (!_dbus_string_init (&result, _DBUS_INT_MAX)) + if (!_dbus_string_init (&result)) _dbus_assert_not_reached ("no memory"); /* the "compact strings" are "^"-terminated not @@ -892,22 +880,15 @@ process_test_data (const char *test_data_dir) } if (!_dbus_string_equal (&result, &expected)) - { - const char *s1; - const char *s2; - - _dbus_string_get_const_data (&result, &s1); - _dbus_string_get_const_data (&expected, &s2); - + { fprintf (stderr, " for line %d got hash %s expected %s\n", - line_no, s1, s2); + line_no, + _dbus_string_get_const_data (&result), + _dbus_string_get_const_data (&expected)); goto failure; } else { - const char *s; - _dbus_string_get_const_data (&result, &s); - /* printf (" Got expected: %s\n", s); */ success_count += 1; } diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 0d98b379..305b488f 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -168,33 +168,18 @@ undo_alignment (DBusRealString *real) } /** - * Initializes a string. The maximum length may be _DBUS_INT_MAX for - * no maximum. The string starts life with zero length. - * The string must eventually be freed with _dbus_string_free(). - * - * @todo the max length feature is useless, because it looks to the - * app like out of memory, and the app might try to "recover" - but - * recovery in this case is impossible, as we can't ever "get more - * memory" - so should delete the max length feature I think. Well, at - * least there's a strong caveat that it can only be used when - * out-of-memory is a permanent fatal error. - * - * @todo we could make this init routine not alloc any memory and - * return void, would simplify a lot of code, however it might - * complexify things elsewhere because _dbus_string_get_data() - * etc. could suddenly fail as they'd need to alloc new memory. + * Initializes a string. The string starts life with zero length. The + * string must eventually be freed with _dbus_string_free(). * * @param str memory to hold the string - * @param max_length the maximum size of the string - * @returns #TRUE on success */ + * @returns #TRUE on success, #FALSE if no memory + */ dbus_bool_t -_dbus_string_init (DBusString *str, - int max_length) +_dbus_string_init (DBusString *str) { DBusRealString *real; _dbus_assert (str != NULL); - _dbus_assert (max_length >= 0); _dbus_assert (sizeof (DBusString) == sizeof (DBusRealString)); @@ -214,9 +199,7 @@ _dbus_string_init (DBusString *str, real->len = 0; real->str[real->len] = '\0'; - real->max_length = max_length; - if (real->max_length > MAX_MAX_LENGTH) - real->max_length = MAX_MAX_LENGTH; + real->max_length = MAX_MAX_LENGTH; real->constant = FALSE; real->locked = FALSE; real->invalid = FALSE; @@ -227,6 +210,23 @@ _dbus_string_init (DBusString *str, return TRUE; } +/* The max length thing is sort of a historical artifact + * from a feature that turned out to be dumb; perhaps + * we should purge it entirely. The problem with + * the feature is that it looks like memory allocation + * failure, but is not a transient or resolvable failure. + */ +static void +set_max_length (DBusString *str, + int max_length) +{ + DBusRealString *real; + + real = (DBusRealString*) str; + + real->max_length = max_length; +} + /** * Initializes a constant string. The value parameter is not copied * (should be static), and the string may never be modified. @@ -409,36 +409,28 @@ open_gap (int len, * function on a const string. * * @param str the string - * @param data_return place to store the returned data + * @returns the data */ -void -_dbus_string_get_data (DBusString *str, - char **data_return) +char* +_dbus_string_get_data (DBusString *str) { DBUS_STRING_PREAMBLE (str); - _dbus_assert (data_return != NULL); - *data_return = real->str; + return real->str; } /** * Gets the raw character buffer from a const string. * - * @todo should return the const char* instead of using an out param; - * the temporary variable encourages a bug where you use const data - * after modifying the string and possibly causing a realloc. - * * @param str the string - * @param data_return location to store returned data + * @returns the string data */ -void -_dbus_string_get_const_data (const DBusString *str, - const char **data_return) +const char* +_dbus_string_get_const_data (const DBusString *str) { DBUS_CONST_STRING_PREAMBLE (str); - _dbus_assert (data_return != NULL); - *data_return = real->str; + return real->str; } /** @@ -450,24 +442,22 @@ _dbus_string_get_const_data (const DBusString *str, * string, not at start + len. * * @param str the string - * @param data_return location to return the buffer * @param start byte offset to return * @param len length of segment to return + * @returns the string data */ -void +char* _dbus_string_get_data_len (DBusString *str, - char **data_return, int start, int len) { DBUS_STRING_PREAMBLE (str); - _dbus_assert (data_return != NULL); _dbus_assert (start >= 0); _dbus_assert (len >= 0); _dbus_assert (start <= real->len); _dbus_assert (len <= real->len - start); - *data_return = real->str + start; + return real->str + start; } /** @@ -478,24 +468,22 @@ _dbus_string_get_data_len (DBusString *str, * after modifying the string and possibly causing a realloc. * * @param str the string - * @param data_return location to return the buffer * @param start byte offset to return * @param len length of segment to return + * @returns the string data */ -void +const char* _dbus_string_get_const_data_len (const DBusString *str, - const char **data_return, int start, int len) { DBUS_CONST_STRING_PREAMBLE (str); - _dbus_assert (data_return != NULL); _dbus_assert (start >= 0); _dbus_assert (len >= 0); _dbus_assert (start <= real->len); _dbus_assert (len <= real->len - start); - *data_return = real->str + start; + return real->str + start; } /** @@ -574,6 +562,7 @@ dbus_bool_t _dbus_string_steal_data (DBusString *str, char **data_return) { + int old_max_length; DBUS_STRING_PREAMBLE (str); _dbus_assert (data_return != NULL); @@ -581,8 +570,10 @@ _dbus_string_steal_data (DBusString *str, *data_return = real->str; + old_max_length = real->max_length; + /* reset the string */ - if (!_dbus_string_init (str, real->max_length)) + if (!_dbus_string_init (str)) { /* hrm, put it back then */ real->str = *data_return; @@ -591,6 +582,8 @@ _dbus_string_steal_data (DBusString *str, return FALSE; } + real->max_length = old_max_length; + return TRUE; } @@ -616,7 +609,6 @@ _dbus_string_steal_data_len (DBusString *str, int len) { DBusString dest; - DBUS_STRING_PREAMBLE (str); _dbus_assert (data_return != NULL); _dbus_assert (start >= 0); @@ -624,9 +616,11 @@ _dbus_string_steal_data_len (DBusString *str, _dbus_assert (start <= real->len); _dbus_assert (len <= real->len - start); - if (!_dbus_string_init (&dest, real->max_length)) + if (!_dbus_string_init (&dest)) return FALSE; + set_max_length (&dest, real->max_length); + if (!_dbus_string_move_len (str, start, len, &dest, 0)) { _dbus_string_free (&dest); @@ -692,9 +686,11 @@ _dbus_string_copy_data_len (const DBusString *str, _dbus_assert (start <= real->len); _dbus_assert (len <= real->len - start); - if (!_dbus_string_init (&dest, real->max_length)) + if (!_dbus_string_init (&dest)) return FALSE; + set_max_length (&dest, real->max_length); + if (!_dbus_string_copy_len (str, start, len, &dest, 0)) { _dbus_string_free (&dest); @@ -2160,7 +2156,7 @@ _dbus_string_base64_decode (const DBusString *source, if (source_len == 0) return TRUE; - if (!_dbus_string_init (&result, _DBUS_INT_MAX)) + if (!_dbus_string_init (&result)) return FALSE; pad_count = 0; @@ -2283,12 +2279,12 @@ _dbus_string_hex_encode (const DBusString *source, _dbus_assert (start <= _dbus_string_get_length (source)); - if (!_dbus_string_init (&result, _DBUS_INT_MAX)) + if (!_dbus_string_init (&result)) return FALSE; retval = FALSE; - _dbus_string_get_const_data (source, (const char**) &p); + p = (const unsigned char*) _dbus_string_get_const_data (source); end = p + _dbus_string_get_length (source); p += start; @@ -2338,13 +2334,13 @@ _dbus_string_hex_decode (const DBusString *source, _dbus_assert (start <= _dbus_string_get_length (source)); - if (!_dbus_string_init (&result, _DBUS_INT_MAX)) + if (!_dbus_string_init (&result)) return FALSE; retval = FALSE; high_bits = TRUE; - _dbus_string_get_const_data (source, (const char**) &p); + p = (const unsigned char*) _dbus_string_get_const_data (source); end = p + _dbus_string_get_length (source); p += start; @@ -2652,13 +2648,13 @@ test_base64_roundtrip (const unsigned char *data, if (len < 0) len = strlen (data); - if (!_dbus_string_init (&orig, _DBUS_INT_MAX)) + if (!_dbus_string_init (&orig)) _dbus_assert_not_reached ("could not init string"); - if (!_dbus_string_init (&encoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&encoded)) _dbus_assert_not_reached ("could not init string"); - if (!_dbus_string_init (&decoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded)) _dbus_assert_not_reached ("could not init string"); if (!_dbus_string_append_len (&orig, data, len)) @@ -2679,7 +2675,7 @@ test_base64_roundtrip (const unsigned char *data, _dbus_string_get_length (&encoded), _dbus_string_get_length (&decoded)); printf ("Original: %s\n", data); - _dbus_string_get_const_data (&decoded, &s); + s = _dbus_string_get_const_data (&decoded); printf ("Decoded: %s\n", s); _dbus_assert_not_reached ("original string not the same as string decoded from base64"); } @@ -2700,13 +2696,13 @@ test_hex_roundtrip (const unsigned char *data, if (len < 0) len = strlen (data); - if (!_dbus_string_init (&orig, _DBUS_INT_MAX)) + if (!_dbus_string_init (&orig)) _dbus_assert_not_reached ("could not init string"); - if (!_dbus_string_init (&encoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&encoded)) _dbus_assert_not_reached ("could not init string"); - if (!_dbus_string_init (&decoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded)) _dbus_assert_not_reached ("could not init string"); if (!_dbus_string_append_len (&orig, data, len)) @@ -2727,7 +2723,7 @@ test_hex_roundtrip (const unsigned char *data, _dbus_string_get_length (&encoded), _dbus_string_get_length (&decoded)); printf ("Original: %s\n", data); - _dbus_string_get_const_data (&decoded, &s); + s = _dbus_string_get_const_data (&decoded); printf ("Decoded: %s\n", s); _dbus_assert_not_reached ("original string not the same as string decoded from base64"); } @@ -2805,8 +2801,10 @@ _dbus_string_test (void) i = 0; while (i < _DBUS_N_ELEMENTS (lens)) { - if (!_dbus_string_init (&str, lens[i])) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); + + set_max_length (&str, lens[i]); test_max_len (&str, lens[i]); _dbus_string_free (&str); @@ -2820,8 +2818,10 @@ _dbus_string_test (void) { int j; - if (!_dbus_string_init (&str, lens[i])) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); + + set_max_length (&str, lens[i]); if (!_dbus_string_set_length (&str, lens[i])) _dbus_assert_not_reached ("failed to set string length"); @@ -2844,7 +2844,7 @@ _dbus_string_test (void) } /* Test appending data */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); i = 0; @@ -2867,7 +2867,7 @@ _dbus_string_test (void) /* Check steal_data */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append (&str, "Hello World")) @@ -2890,7 +2890,7 @@ _dbus_string_test (void) i = _dbus_string_get_length (&str); - if (!_dbus_string_init (&other, _DBUS_INT_MAX)) + if (!_dbus_string_init (&other)) _dbus_assert_not_reached ("could not init string"); if (!_dbus_string_move (&str, 0, &other, 0)) @@ -2926,7 +2926,7 @@ _dbus_string_test (void) i = _dbus_string_get_length (&str); - if (!_dbus_string_init (&other, _DBUS_INT_MAX)) + if (!_dbus_string_init (&other)) _dbus_assert_not_reached ("could not init string"); if (!_dbus_string_copy (&str, 0, &other, 0)) @@ -2956,7 +2956,7 @@ _dbus_string_test (void) /* Check replace */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append (&str, "Hello World")) @@ -2964,7 +2964,7 @@ _dbus_string_test (void) i = _dbus_string_get_length (&str); - if (!_dbus_string_init (&other, _DBUS_INT_MAX)) + if (!_dbus_string_init (&other)) _dbus_assert_not_reached ("could not init string"); if (!_dbus_string_replace_len (&str, 0, _dbus_string_get_length (&str), @@ -3001,7 +3001,7 @@ _dbus_string_test (void) /* Check append/get unichar */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); ch = 0; @@ -3017,7 +3017,7 @@ _dbus_string_test (void) /* Check insert/set/get byte */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append (&str, "Hello")) @@ -3054,7 +3054,7 @@ _dbus_string_test (void) /* Check append/parse int/double */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append_int (&str, 27)) @@ -3070,7 +3070,7 @@ _dbus_string_test (void) _dbus_string_free (&str); - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append_double (&str, 50.3)) @@ -3087,7 +3087,7 @@ _dbus_string_test (void) _dbus_string_free (&str); /* Test find */ - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("failed to init string"); if (!_dbus_string_append (&str, "Hello")) diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index 3a517e94..ba0fcf85 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -45,8 +45,7 @@ struct DBusString unsigned int dummy8 : 3; /**< placeholder */ }; -dbus_bool_t _dbus_string_init (DBusString *str, - int max_length); +dbus_bool_t _dbus_string_init (DBusString *str); void _dbus_string_init_const (DBusString *str, const char *value); void _dbus_string_init_const_len (DBusString *str, @@ -55,16 +54,12 @@ void _dbus_string_init_const_len (DBusString *str, void _dbus_string_free (DBusString *str); void _dbus_string_lock (DBusString *str); -void _dbus_string_get_data (DBusString *str, - char **data_return); -void _dbus_string_get_const_data (const DBusString *str, - const char **data_return); -void _dbus_string_get_data_len (DBusString *str, - char **data_return, +char* _dbus_string_get_data (DBusString *str); +const char* _dbus_string_get_const_data (const DBusString *str); +char* _dbus_string_get_data_len (DBusString *str, int start, int len); -void _dbus_string_get_const_data_len (const DBusString *str, - const char **data_return, +const char* _dbus_string_get_const_data_len (const DBusString *str, int start, int len); void _dbus_string_set_byte (DBusString *str, diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index c23d8481..f551c4bf 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -96,7 +96,7 @@ _dbus_setenv (const char *varname, const char *value) DBusString str; char *putenv_value; - if (!_dbus_string_init (&str, _DBUS_INT_MAX)) + if (!_dbus_string_init (&str)) return FALSE; if (!_dbus_string_append (&str, varname) || @@ -158,7 +158,7 @@ _dbus_read (int fd, return -1; } - _dbus_string_get_data_len (buffer, &data, start, count); + data = _dbus_string_get_data_len (buffer, start, count); again: @@ -208,7 +208,7 @@ _dbus_write (int fd, const char *data; int bytes_written; - _dbus_string_get_const_data_len (buffer, &data, start, len); + data = _dbus_string_get_const_data_len (buffer, start, len); again: @@ -267,10 +267,10 @@ _dbus_write_two (int fd, const char *data2; int bytes_written; - _dbus_string_get_const_data_len (buffer1, &data1, start1, len1); + data1 = _dbus_string_get_const_data_len (buffer1, start1, len1); if (buffer2 != NULL) - _dbus_string_get_const_data_len (buffer2, &data2, start2, len2); + data2 = _dbus_string_get_const_data_len (buffer2, start2, len2); else { data2 = NULL; @@ -854,7 +854,7 @@ _dbus_string_append_int (DBusString *str, if (!_dbus_string_lengthen (str, MAX_LONG_LEN)) return FALSE; - _dbus_string_get_data_len (str, &buf, orig_len, MAX_LONG_LEN); + buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN); snprintf (buf, MAX_LONG_LEN, "%ld", value); @@ -892,7 +892,7 @@ _dbus_string_append_uint (DBusString *str, if (!_dbus_string_lengthen (str, MAX_ULONG_LEN)) return FALSE; - _dbus_string_get_data_len (str, &buf, orig_len, MAX_ULONG_LEN); + buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN); snprintf (buf, MAX_ULONG_LEN, "%lu", value); @@ -929,7 +929,7 @@ _dbus_string_append_double (DBusString *str, if (!_dbus_string_lengthen (str, MAX_DOUBLE_LEN)) return FALSE; - _dbus_string_get_data_len (str, &buf, orig_len, MAX_DOUBLE_LEN); + buf = _dbus_string_get_data_len (str, orig_len, MAX_DOUBLE_LEN); snprintf (buf, MAX_LONG_LEN, "%g", value); @@ -967,8 +967,8 @@ _dbus_string_parse_int (const DBusString *str, const char *p; char *end; - _dbus_string_get_const_data_len (str, &p, start, - _dbus_string_get_length (str) - start); + p = _dbus_string_get_const_data_len (str, start, + _dbus_string_get_length (str) - start); end = NULL; errno = 0; @@ -1006,8 +1006,8 @@ _dbus_string_parse_uint (const DBusString *str, const char *p; char *end; - _dbus_string_get_const_data_len (str, &p, start, - _dbus_string_get_length (str) - start); + p = _dbus_string_get_const_data_len (str, start, + _dbus_string_get_length (str) - start); end = NULL; errno = 0; @@ -1051,8 +1051,8 @@ _dbus_string_parse_double (const DBusString *str, _dbus_warn ("_dbus_string_parse_double() needs to be made locale-independent\n"); - _dbus_string_get_const_data_len (str, &p, start, - _dbus_string_get_length (str) - start); + p = _dbus_string_get_const_data_len (str, start, + _dbus_string_get_length (str) - start); end = NULL; errno = 0; @@ -1151,7 +1151,7 @@ get_user_info (const DBusString *username, } if (username != NULL) - _dbus_string_get_const_data (username, &username_c_str); + username_c_str = _dbus_string_get_const_data (username); else username_c_str = NULL; @@ -1284,13 +1284,13 @@ _dbus_user_info_from_current_process (const DBusString **username, if (initialized_generation != _dbus_current_generation) { - if (!_dbus_string_init (&u.name, _DBUS_INT_MAX)) + if (!_dbus_string_init (&u.name)) { _DBUS_UNLOCK (user_info); return FALSE; } - if (!_dbus_string_init (&u.dir, _DBUS_INT_MAX)) + if (!_dbus_string_init (&u.dir)) { _dbus_string_free (&u.name); _DBUS_UNLOCK (user_info); @@ -1448,8 +1448,8 @@ _dbus_get_group_id (const DBusString *group_name, unsigned long *gid) { const char *group_c_str; - - _dbus_string_get_const_data (group_name, &group_c_str); + + group_c_str = _dbus_string_get_const_data (group_name); /* For now assuming that the getgrnam() and getgrgid() flavors * always correspond to the pwnam flavors, if not we have @@ -1533,7 +1533,7 @@ _dbus_get_groups (unsigned long uid, retval = FALSE; - if (!_dbus_string_init (&username, _DBUS_INT_MAX)) + if (!_dbus_string_init (&username)) return FALSE; if (!get_user_info (NULL, uid, &creds, @@ -1541,7 +1541,7 @@ _dbus_get_groups (unsigned long uid, creds.gid < 0) goto out; - _dbus_string_get_const_data (&username, &username_c); + username_c = _dbus_string_get_const_data (&username); #ifdef HAVE_GETGROUPLIST { @@ -1839,7 +1839,7 @@ _dbus_file_get_contents (DBusString *str, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); /* O_BINARY useful on Cygwin */ fd = open (filename_c, O_RDONLY | O_BINARY); @@ -1975,7 +1975,7 @@ _dbus_string_save_to_file (const DBusString *str, retval = FALSE; need_unlink = FALSE; - if (!_dbus_string_init (&tmp_filename, _DBUS_INT_MAX)) + if (!_dbus_string_init (&tmp_filename)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return FALSE; @@ -1999,8 +1999,8 @@ _dbus_string_save_to_file (const DBusString *str, return FALSE; } - _dbus_string_get_const_data (filename, &filename_c); - _dbus_string_get_const_data (&tmp_filename, &tmp_filename_c); + filename_c = _dbus_string_get_const_data (filename); + tmp_filename_c = _dbus_string_get_const_data (&tmp_filename); fd = open (tmp_filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT, 0600); @@ -2096,7 +2096,7 @@ _dbus_create_file_exclusively (const DBusString *filename, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT, 0600); @@ -2139,7 +2139,7 @@ _dbus_delete_file (const DBusString *filename, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); if (unlink (filename_c) < 0) { @@ -2168,7 +2168,7 @@ _dbus_create_directory (const DBusString *filename, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); if (mkdir (filename_c, 0700) < 0) { @@ -2244,7 +2244,7 @@ _dbus_directory_open (const DBusString *filename, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); d = opendir (filename_c); if (d == NULL) @@ -2894,7 +2894,7 @@ _dbus_stat (const DBusString *filename, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); if (stat (filename_c, &sb) < 0) { diff --git a/dbus/dbus-transport-debug.c b/dbus/dbus-transport-debug.c index a1b2a64a..5b250d7f 100644 --- a/dbus/dbus-transport-debug.c +++ b/dbus/dbus-transport-debug.c @@ -328,7 +328,7 @@ _dbus_transport_debug_client_new (const char *server_name, return NULL; } - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index 81672de5..5e37a007 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -977,12 +977,10 @@ _dbus_transport_new_for_fd (int fd, if (unix_transport == NULL) return NULL; - if (!_dbus_string_init (&unix_transport->encoded_outgoing, - _DBUS_INT_MAX)) + if (!_dbus_string_init (&unix_transport->encoded_outgoing)) goto failed_0; - if (!_dbus_string_init (&unix_transport->encoded_incoming, - _DBUS_INT_MAX)) + if (!_dbus_string_init (&unix_transport->encoded_incoming)) goto failed_1; unix_transport->write_watch = _dbus_watch_new (fd, @@ -1042,7 +1040,7 @@ _dbus_transport_new_for_domain_socket (const char *path, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; @@ -1102,7 +1100,7 @@ _dbus_transport_new_for_tcp_socket (const char *host, _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index a7aecc3f..96bc6b64 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -636,7 +636,7 @@ recover_unused_bytes (DBusTransport *transport) DBusString *buffer; int orig_len; - if (!_dbus_string_init (&plaintext, _DBUS_INT_MAX)) + if (!_dbus_string_init (&plaintext)) goto nomem; _dbus_auth_get_unused_bytes (transport->auth, diff --git a/test/break-loader.c b/test/break-loader.c index 8aa15a80..e2ce6819 100644 --- a/test/break-loader.c +++ b/test/break-loader.c @@ -124,7 +124,7 @@ try_mutated_data (const DBusString *data) failed = FALSE; - if (!_dbus_string_init (&filename, _DBUS_INT_MAX) || + if (!_dbus_string_init (&filename) || !_dbus_string_copy (&failure_dir, 0, &filename, 0) || !_dbus_string_append_byte (&filename, '/')) @@ -153,14 +153,11 @@ try_mutated_data (const DBusString *data) if (failed) { - const char *filename_c; DBusError error; _dbus_string_append (&filename, ".message-raw"); - _dbus_string_get_const_data (&filename, &filename_c); - printf ("Child failed, writing %s\n", - filename_c); + printf ("Child failed, writing %s\n", _dbus_string_get_const_data (&filename)); dbus_error_init (&error); if (!_dbus_string_save_to_file (data, &filename, &error)) @@ -315,7 +312,7 @@ randomly_modify_length (const DBusString *orig_data, if (_dbus_string_get_length (mutated) < 12) return; - _dbus_string_get_const_data (mutated, &d); + d = _dbus_string_get_const_data (mutated); if (!(*d == DBUS_LITTLE_ENDIAN || *d == DBUS_BIG_ENDIAN)) @@ -371,7 +368,7 @@ randomly_set_extreme_ints (const DBusString *orig_data, if (_dbus_string_get_length (mutated) < 12) return; - _dbus_string_get_const_data (mutated, &d); + d = _dbus_string_get_const_data (mutated); if (!(*d == DBUS_LITTLE_ENDIAN || *d == DBUS_BIG_ENDIAN)) @@ -443,14 +440,14 @@ find_breaks_based_on (const DBusString *filename, dbus_bool_t retval; int i; - _dbus_string_get_const_data (filename, &filename_c); + filename_c = _dbus_string_get_const_data (filename); retval = FALSE; - if (!_dbus_string_init (&orig_data, _DBUS_INT_MAX)) + if (!_dbus_string_init (&orig_data)) _dbus_assert_not_reached ("could not allocate string\n"); - if (!_dbus_string_init (&mutated, _DBUS_INT_MAX)) + if (!_dbus_string_init (&mutated)) _dbus_assert_not_reached ("could not allocate string\n"); if (!dbus_internal_do_not_use_load_message_file (filename, is_raw, @@ -562,7 +559,7 @@ get_random_seed (void) seed = 0; - if (!_dbus_string_init (&bytes, _DBUS_INT_MAX)) + if (!_dbus_string_init (&bytes)) exit (1); fd = open ("/dev/urandom", O_RDONLY); @@ -574,7 +571,7 @@ get_random_seed (void) close (fd); - _dbus_string_get_const_data (&bytes, &s); + s = _dbus_string_get_const_data (&bytes); seed = * (unsigned int*) s; goto out; @@ -615,7 +612,7 @@ main (int argc, total_failures_found = 0; total_attempts = 0; - if (!_dbus_string_init (&failure_dir, _DBUS_INT_MAX)) + if (!_dbus_string_init (&failure_dir)) return 1; /* so you can leave it overnight safely */ @@ -637,7 +634,7 @@ main (int argc, if (!_dbus_string_append_uint (&failure_dir, seed)) return 1; - _dbus_string_get_const_data (&failure_dir, &failure_dir_c); + failure_dir_c = _dbus_string_get_const_data (&failure_dir); if (mkdir (failure_dir_c, 0700) < 0) { diff --git a/test/unbase64.c b/test/unbase64.c index f3894bd8..2dc232f3 100644 --- a/test/unbase64.c +++ b/test/unbase64.c @@ -24,10 +24,10 @@ main (int argc, _dbus_string_init_const (&filename, argv[1]); - if (!_dbus_string_init (&contents, _DBUS_INT_MAX)) + if (!_dbus_string_init (&contents)) return 1; - if (!_dbus_string_init (&decoded, _DBUS_INT_MAX)) + if (!_dbus_string_init (&decoded)) return 1; dbus_error_init (&error); @@ -42,7 +42,7 @@ main (int argc, &decoded, 0)) return 1; - _dbus_string_get_const_data (&decoded, &s); + s = _dbus_string_get_const_data (&decoded); fputs (s, stdout); -- cgit