summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2008-06-20 18:08:47 (GMT)
committerColin Walters <walters@verbum.org>2008-06-20 18:08:47 (GMT)
commit4c7e60e3ff4148a181a496f85b491e8cb39d7e46 (patch)
treefee6eb63728a27bb02acad5f759fc779d5325df3
parent2514b84b3644223653018cd75d0d6e1459a7ab70 (diff)
downloaddbus-glib-4c7e60e3ff4148a181a496f85b491e8cb39d7e46.tar.gz
dbus-glib-4c7e60e3ff4148a181a496f85b491e8cb39d7e46.tar.xz
Bug 10373: Use of deprecated API (was used incorrectly)
* dbus/dbus-gvalue.c: The use of dbus_message_iter_get_array_len here is incorrect; we don't want to allocate a number of pointers based on the length of the strings. Instead, we now use the regular GArray type which handles reallocating as size increases appropriately.
-rw-r--r--dbus/dbus-gvalue.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/dbus/dbus-gvalue.c b/dbus/dbus-gvalue.c
index fa8382c..a18067c 100644
--- a/dbus/dbus-gvalue.c
+++ b/dbus/dbus-gvalue.c
@@ -712,9 +712,7 @@ demarshal_strv (DBusGValueMarshalCtx *context,
{
DBusMessageIter subiter;
int current_type;
- char **ret;
- int len;
- int i;
+ GArray *arr;
current_type = dbus_message_iter_get_arg_type (iter);
if (current_type != DBUS_TYPE_ARRAY)
@@ -739,24 +737,23 @@ demarshal_strv (DBusGValueMarshalCtx *context,
return FALSE;
}
- len = dbus_message_iter_get_array_len (&subiter);
- g_assert (len >= 0);
- ret = g_malloc (sizeof (char *) * (len + 1));
-
- i = 0;
+ arr = g_array_new (TRUE, FALSE, sizeof (char *));
+
while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
{
- g_assert (i < len);
g_assert (current_type == DBUS_TYPE_STRING);
+ const char *str;
+ char *copy;
- dbus_message_iter_get_basic (&subiter, &(ret[i]));
- ret[i] = g_strdup (ret[i]);
+ dbus_message_iter_get_basic (&subiter, &str);
+ copy = g_strdup (str);
+ g_array_append_val (arr, copy);
dbus_message_iter_next (&subiter);
- i++;
}
- ret[i] = NULL;
- g_value_set_boxed_take_ownership (value, ret);
+
+ g_value_set_boxed_take_ownership (value, arr->data);
+ g_array_free (arr, FALSE);
return TRUE;
}