]> granicus.if.org Git - json-c/commitdiff
Merge branch 'fixes-for-upstream' of https://github.com/doctaweeks/json-c into doctaw...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 23 May 2016 02:08:28 +0000 (02:08 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 23 May 2016 02:08:28 +0000 (02:08 +0000)
1  2 
arraylist.c
arraylist.h
json_object.c
json_object.h

diff --cc arraylist.c
index 1789ad264e36f714b9dcbdf14af5c7c5a981bc86,54fd2bb36ff234298843c84497f6fed87d4edd05..a02266e8266b174f2660b8e79ffc52933730300a
@@@ -58,23 -56,16 +58,23 @@@ array_list_get_idx(struct array_list *a
    return arr->array[i];
  }
  
- static int array_list_expand_internal(struct array_list *arr, int max)
+ static int array_list_expand_internal(struct array_list *arr, size_t max)
  {
    void *t;
-   int new_size;
+   size_t new_size;
  
    if(max < arr->size) return 0;
 -  new_size = arr->size << 1;
 -  if (new_size < max)
 +  /* Avoid undefined behaviour on int32 overflow */
 +  if( arr->size >= INT_MAX / 2 )
      new_size = max;
 -  if(!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
 +  else
 +  {
 +    new_size = arr->size << 1;
 +    if (new_size < max)
 +      new_size = max;
 +  }
 +  if((size_t)new_size > (~((size_t)0)) / sizeof(void*)) return -1;
 +  if(!(t = realloc(arr->array, ((size_t)new_size)*sizeof(void*)))) return -1;
    arr->array = (void**)t;
    (void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
    arr->size = new_size;
@@@ -82,9 -73,8 +82,9 @@@
  }
  
  int
- array_list_put_idx(struct array_list *arr, int idx, void *data)
+ array_list_put_idx(struct array_list *arr, size_t idx, void *data)
  {
 +  if( idx < 0 || idx > INT_MAX - 1 ) return -1;
    if(array_list_expand_internal(arr, idx+1)) return -1;
    if(arr->array[idx]) arr->free_fn(arr->array[idx]);
    arr->array[idx] = data;
diff --cc arraylist.h
Simple merge
diff --cc json_object.c
index 46701e7674f623671235c325e2a6a51844b26701,8e7e8a1b3bc2646809184411fd4273cc90b53859..b0b381e304676ec973710160f62bbcf85e0b9d45
@@@ -975,7 -959,7 +975,7 @@@ struct json_object* json_object_array_b
        return *result;
  }
  
- int json_object_array_length(const struct json_object *jso)
 -size_t json_object_array_length(struct json_object *jso)
++size_t json_object_array_length(const struct json_object *jso)
  {
        return array_list_length(jso->o.c_array);
  }
@@@ -991,8 -975,8 +991,8 @@@ int json_object_array_put_idx(struct js
        return array_list_put_idx(jso->o.c_array, idx, val);
  }
  
 -struct json_object* json_object_array_get_idx(struct json_object *jso,
 +struct json_object* json_object_array_get_idx(const struct json_object *jso,
-                                             int idx)
+                                             size_t idx)
  {
        return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
  }
diff --cc json_object.h
index a89de44df19241d72a7becb3335da00ed23803f4,f8106781fa13524a8e85bc161eef207a3c527208..46540b742116e229fe0f08d75009442d4b712a20
@@@ -457,7 -449,7 +457,7 @@@ extern struct array_list* json_object_g
   * @param obj the json_object instance
   * @returns an int
   */
- extern int json_object_array_length(const struct json_object *obj);
 -extern size_t json_object_array_length(struct json_object *obj);
++extern size_t json_object_array_length(const struct json_object *obj);
  
  /** Sorts the elements of jso of type json_type_array
  *
@@@ -523,22 -515,9 +523,22 @@@ extern int json_object_array_put_idx(st
   * @param idx the index to get the element at
   * @returns the json_object at the specified index (or NULL)
   */
 -extern struct json_object* json_object_array_get_idx(struct json_object *obj,
 +extern struct json_object* json_object_array_get_idx(const struct json_object *obj,
-                                                    int idx);
+                                                    size_t idx);
  
 +/** Delete an elements from a specified index in an array (a json_object of type json_type_array)
 + *
 + * The reference count will be decremented for each of the deleted objects.  If there
 + * are no more owners of an element that is being deleted, then the value is 
 + * freed.  Otherwise, the reference to the value will remain in memory.
 + *
 + * @param obj the json_object instance
 + * @param idx the index to start deleting elements at
 + * @param count the number of elements to delete
 + * @returns 0 if the elements were successfully deleted
 + */
 +extern int json_object_array_del_idx(struct json_object *obj, int idx, int count);
 +
  /* json_bool type methods */
  
  /** Create a new empty json_object of type json_type_boolean