From d5b7d7a78c0fb2e41d5966a0778b08f8d8e35ea4 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 30 Jan 2005 23:29:50 +0000 Subject: 2005-01-30 Havoc Pennington * tools/dbus-names-model.c (have_names_notify): fix this * dbus/dbus-message.c (_dbus_message_iter_get_args_valist): clean up the string array handling a bit --- dbus/dbus-message.c | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'dbus/dbus-message.c') diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 0d816595..46a30b6f 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1765,7 +1765,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, spec_element_type == DBUS_TYPE_OBJECT_PATH) { char ***str_array_p; - int i; + int n_elements; char **str_array; str_array_p = va_arg (var_args, char***); @@ -1777,14 +1777,14 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, /* Count elements in the array */ _dbus_type_reader_recurse (&real->u.reader, &array); - i = 0; - if (_dbus_type_reader_has_next (&array)) + n_elements = 0; + while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID) { - while (_dbus_type_reader_next (&array)) - ++i; + ++n_elements; + _dbus_type_reader_next (&array); } - str_array = dbus_new0 (char*, i + 1); + str_array = dbus_new0 (char*, n_elements + 1); if (str_array == NULL) { _DBUS_SET_OOM (error); @@ -1795,29 +1795,32 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, _dbus_type_reader_recurse (&real->u.reader, &array); i = 0; - if (_dbus_type_reader_has_next (&array)) + while (i < n_elements) { - do + const char *s; + _dbus_type_reader_read_basic (&array, + &s); + + str_array[i] = _dbus_strdup (s); + if (str_array[i] == NULL) { - const char *s; - _dbus_type_reader_read_basic (&array, - &s); - - str_array[i] = _dbus_strdup (s); - if (str_array[i] == NULL) - { - dbus_free_string_array (str_array); - _DBUS_SET_OOM (error); - goto out; - } - - ++i; + dbus_free_string_array (str_array); + _DBUS_SET_OOM (error); + goto out; } - while (_dbus_type_reader_next (&array)); + + ++i; + + if (!_dbus_type_reader_next (&array)) + _dbus_assert (i == n_elements); } + _dbus_assert (_dbus_type_reader_get_current_type (&array) == DBUS_TYPE_INVALID); + _dbus_assert (i == n_elements); + _dbus_assert (str_array[i] == NULL); + *str_array_p = str_array; - *n_elements_p = i; + *n_elements_p = n_elements; } #ifndef DBUS_DISABLE_CHECKS else -- cgit