]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
fix off by one error message (#13305)
authorChengwei Yang <chengwei.yang@intel.com>
Sun, 29 Sep 2013 10:10:33 +0000 (18:10 +0800)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 8 Oct 2013 10:58:45 +0000 (11:58 +0100)
This patch is based on the patch created by John (J5) Palmieri
<johnp@redhat.com> plus to fix array of string assignment.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13305
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
dbus/dbus-message.c

index 13edeb7bd89335859e6a38bfaa87284d709c8c92..9546da12546ec3ca258f6a3d635ea67da1270ec5 100644 (file)
@@ -800,7 +800,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
                                     va_list          var_args)
 {
   DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
-  int spec_type, msg_type, i;
+  int spec_type, msg_type, i, j;
   dbus_bool_t retval;
 
   _dbus_assert (_dbus_message_iter_check (real));
@@ -936,30 +936,30 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
               /* Now go through and dup each string */
               _dbus_type_reader_recurse (&real->u.reader, &array);
 
-              i = 0;
-              while (i < n_elements)
+              j = 0;
+              while (j < n_elements)
                 {
                   const char *s;
                   _dbus_type_reader_read_basic (&array,
                                                 (void *) &s);
                   
-                  str_array[i] = _dbus_strdup (s);
-                  if (str_array[i] == NULL)
+                  str_array[j] = _dbus_strdup (s);
+                  if (str_array[j] == NULL)
                     {
                       dbus_free_string_array (str_array);
                       _DBUS_SET_OOM (error);
                       goto out;
                     }
                   
-                  ++i;
+                  ++j;
                   
                   if (!_dbus_type_reader_next (&array))
-                    _dbus_assert (i == n_elements);
+                    _dbus_assert (j == 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);
+              _dbus_assert (j == n_elements);
+              _dbus_assert (str_array[j] == NULL);
 
               *str_array_p = str_array;
               *n_elements_p = n_elements;
@@ -986,7 +986,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
       if (!_dbus_type_reader_next (&real->u.reader) && spec_type != DBUS_TYPE_INVALID)
         {
           dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
-                          "Message has only %d arguments, but more were expected", i);
+                          "Message has only %d arguments, but more were expected", i + 1);
           goto out;
         }