mirror of
https://github.com/json-c/json-c.git
synced 2026-04-04 12:59:07 +08:00
Merge branch 'fixes-for-upstream' of https://github.com/doctaweeks/json-c into doctaweeks-fixes-for-upstream
This commit is contained in:
12
arraylist.c
12
arraylist.c
@@ -44,7 +44,7 @@ array_list_new(array_list_free_fn *free_fn)
|
|||||||
extern void
|
extern void
|
||||||
array_list_free(struct array_list *arr)
|
array_list_free(struct array_list *arr)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
for(i = 0; i < arr->length; i++)
|
for(i = 0; i < arr->length; i++)
|
||||||
if(arr->array[i]) arr->free_fn(arr->array[i]);
|
if(arr->array[i]) arr->free_fn(arr->array[i]);
|
||||||
free(arr->array);
|
free(arr->array);
|
||||||
@@ -52,16 +52,16 @@ array_list_free(struct array_list *arr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
array_list_get_idx(struct array_list *arr, int i)
|
array_list_get_idx(struct array_list *arr, size_t i)
|
||||||
{
|
{
|
||||||
if(i >= arr->length) return NULL;
|
if(i >= arr->length) return NULL;
|
||||||
return arr->array[i];
|
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;
|
void *t;
|
||||||
int new_size;
|
size_t new_size;
|
||||||
|
|
||||||
if(max < arr->size) return 0;
|
if(max < arr->size) return 0;
|
||||||
/* Avoid undefined behaviour on int32 overflow */
|
/* Avoid undefined behaviour on int32 overflow */
|
||||||
@@ -82,7 +82,7 @@ static int array_list_expand_internal(struct array_list *arr, int max)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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( idx < 0 || idx > INT_MAX - 1 ) return -1;
|
||||||
if(array_list_expand_internal(arr, idx+1)) return -1;
|
if(array_list_expand_internal(arr, idx+1)) return -1;
|
||||||
@@ -111,7 +111,7 @@ void* array_list_bsearch(const void **key, struct array_list *arr,
|
|||||||
sort_fn);
|
sort_fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
size_t
|
||||||
array_list_length(struct array_list *arr)
|
array_list_length(struct array_list *arr)
|
||||||
{
|
{
|
||||||
return arr->length;
|
return arr->length;
|
||||||
|
|||||||
10
arraylist.h
10
arraylist.h
@@ -23,8 +23,8 @@ typedef void (array_list_free_fn) (void *data);
|
|||||||
struct array_list
|
struct array_list
|
||||||
{
|
{
|
||||||
void **array;
|
void **array;
|
||||||
int length;
|
size_t length;
|
||||||
int size;
|
size_t size;
|
||||||
array_list_free_fn *free_fn;
|
array_list_free_fn *free_fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,15 +35,15 @@ extern void
|
|||||||
array_list_free(struct array_list *al);
|
array_list_free(struct array_list *al);
|
||||||
|
|
||||||
extern void*
|
extern void*
|
||||||
array_list_get_idx(struct array_list *al, int i);
|
array_list_get_idx(struct array_list *al, size_t i);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
array_list_put_idx(struct array_list *al, int i, void *data);
|
array_list_put_idx(struct array_list *al, size_t i, void *data);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
array_list_add(struct array_list *al, void *data);
|
array_list_add(struct array_list *al, void *data);
|
||||||
|
|
||||||
extern int
|
extern size_t
|
||||||
array_list_length(struct array_list *al);
|
array_list_length(struct array_list *al);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
|
|||||||
@@ -879,7 +879,7 @@ static int json_object_array_to_json_string(struct json_object* jso,
|
|||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
int had_children = 0;
|
int had_children = 0;
|
||||||
int ii;
|
size_t ii;
|
||||||
sprintbuf(pb, "[");
|
sprintbuf(pb, "[");
|
||||||
if (flags & JSON_C_TO_STRING_PRETTY)
|
if (flags & JSON_C_TO_STRING_PRETTY)
|
||||||
sprintbuf(pb, "\n");
|
sprintbuf(pb, "\n");
|
||||||
@@ -975,7 +975,7 @@ struct json_object* json_object_array_bsearch(
|
|||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int json_object_array_length(const struct json_object *jso)
|
size_t json_object_array_length(const struct json_object *jso)
|
||||||
{
|
{
|
||||||
return array_list_length(jso->o.c_array);
|
return array_list_length(jso->o.c_array);
|
||||||
}
|
}
|
||||||
@@ -985,14 +985,14 @@ int json_object_array_add(struct json_object *jso,struct json_object *val)
|
|||||||
return array_list_add(jso->o.c_array, val);
|
return array_list_add(jso->o.c_array, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int json_object_array_put_idx(struct json_object *jso, int idx,
|
int json_object_array_put_idx(struct json_object *jso, size_t idx,
|
||||||
struct json_object *val)
|
struct json_object *val)
|
||||||
{
|
{
|
||||||
return array_list_put_idx(jso->o.c_array, idx, val);
|
return array_list_put_idx(jso->o.c_array, idx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_object* json_object_array_get_idx(const 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);
|
return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ extern struct array_list* json_object_get_array(const struct json_object *obj);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns an int
|
* @returns an int
|
||||||
*/
|
*/
|
||||||
extern int json_object_array_length(const 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
|
/** Sorts the elements of jso of type json_type_array
|
||||||
*
|
*
|
||||||
@@ -515,7 +515,7 @@ extern int json_object_array_add(struct json_object *obj,
|
|||||||
* @param idx the index to insert the element at
|
* @param idx the index to insert the element at
|
||||||
* @param val the json_object to be added
|
* @param val the json_object to be added
|
||||||
*/
|
*/
|
||||||
extern int json_object_array_put_idx(struct json_object *obj, int idx,
|
extern int json_object_array_put_idx(struct json_object *obj, size_t idx,
|
||||||
struct json_object *val);
|
struct json_object *val);
|
||||||
|
|
||||||
/** Get the element at specificed index of the array (a json_object of type json_type_array)
|
/** Get the element at specificed index of the array (a json_object of type json_type_array)
|
||||||
@@ -524,7 +524,7 @@ extern int json_object_array_put_idx(struct json_object *obj, int idx,
|
|||||||
* @returns the json_object at the specified index (or NULL)
|
* @returns the json_object at the specified index (or NULL)
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_array_get_idx(const 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)
|
/** Delete an elements from a specified index in an array (a json_object of type json_type_array)
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user