On 23.10.2012 12:36, Patrik Flykt wrote:

        Hi,

On Tue, 2012-10-23 at 10:42 +0200, Daniel Wagner wrote:
+static int parse_context(DBusMessage *msg, unsigned char **context,
+                               unsigned int *size)
+{
+       DBusMessageIter iter, array;
+       unsigned char *ctx;
+       int i = 0;
+
+       dbus_message_iter_init(msg, &iter);
+       dbus_message_iter_recurse(&iter, &array);
+       while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_BYTE) {
+               i++;
+
+               dbus_message_iter_next(&array);
+       }
+
+       *size = i;
+       if (i == 0)
+               return 0;
+
+       ctx = g_try_malloc((gsize) *size);
+       if (ctx == NULL)
+               return -ENOMEM;
+
+       i = 0;
+       dbus_message_iter_init(msg, &iter);
+       dbus_message_iter_recurse(&iter, &array);
+       while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_BYTE) {
+               dbus_message_iter_get_basic(&array, &ctx[i]);
+

So it's an array of bytes including a NULL byte as it seems.

Ok.

+               i++;
+               dbus_message_iter_next(&array);
+       }
+
+       *context = ctx;
+
+       return 0;
+}
+

Perhaps the parsed char ** could be returned here?

What do you mean with 'parsed char **'? parse_context(ctx)?

Are we ever going to be interested in the return value of
parse_context() as it is always zero, or could we just 'return ctx;'
instead?

If the only error is ENOMEM then we could just return the allocated
buffer. The callee can then figure if ENOMEM or valid happened.

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to