From 45c56b80c4b8a121e6eecbbe5cfeae74060b0468 Mon Sep 17 00:00:00 2001 From: "Daniel M. Weeks" Date: Fri, 22 Aug 2014 10:56:59 -0400 Subject: [PATCH 1/2] Use size_t for array list length and size --- arraylist.c | 12 ++++++------ arraylist.h | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arraylist.c b/arraylist.c index 8efe006..54fd2bb 100644 --- a/arraylist.c +++ b/arraylist.c @@ -42,7 +42,7 @@ array_list_new(array_list_free_fn *free_fn) extern void array_list_free(struct array_list *arr) { - int i; + size_t i; for(i = 0; i < arr->length; i++) if(arr->array[i]) arr->free_fn(arr->array[i]); free(arr->array); @@ -50,16 +50,16 @@ array_list_free(struct array_list *arr) } 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; 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; @@ -73,7 +73,7 @@ static int array_list_expand_internal(struct array_list *arr, int max) } 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(array_list_expand_internal(arr, idx+1)) return -1; if(arr->array[idx]) arr->free_fn(arr->array[idx]); @@ -101,7 +101,7 @@ void* array_list_bsearch(const void **key, struct array_list *arr, sort_fn); } -int +size_t array_list_length(struct array_list *arr) { return arr->length; diff --git a/arraylist.h b/arraylist.h index caecdfa..95c38e2 100644 --- a/arraylist.h +++ b/arraylist.h @@ -23,8 +23,8 @@ typedef void (array_list_free_fn) (void *data); struct array_list { void **array; - int length; - int size; + size_t length; + size_t size; array_list_free_fn *free_fn; }; @@ -35,15 +35,15 @@ extern void array_list_free(struct array_list *al); 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 -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 array_list_add(struct array_list *al, void *data); -extern int +extern size_t array_list_length(struct array_list *al); extern void From 92e9a5032bc38ffef09b33991f035a423d5f79a4 Mon Sep 17 00:00:00 2001 From: "Daniel M. Weeks" Date: Fri, 22 Aug 2014 12:16:45 -0400 Subject: [PATCH 2/2] Use size_t for json object array ops --- json_object.c | 8 ++++---- json_object.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/json_object.c b/json_object.c index 9ac22a3..8e7e8a1 100644 --- a/json_object.c +++ b/json_object.c @@ -868,7 +868,7 @@ static int json_object_array_to_json_string(struct json_object* jso, int flags) { int had_children = 0; - int ii; + size_t ii; sprintbuf(pb, "["); if (flags & JSON_C_TO_STRING_PRETTY) sprintbuf(pb, "\n"); @@ -959,7 +959,7 @@ struct json_object* json_object_array_bsearch( return *result; } -int json_object_array_length(struct json_object *jso) +size_t json_object_array_length(struct json_object *jso) { return array_list_length(jso->o.c_array); } @@ -969,14 +969,14 @@ int json_object_array_add(struct json_object *jso,struct json_object *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) { return array_list_put_idx(jso->o.c_array, idx, val); } struct json_object* json_object_array_get_idx(struct json_object *jso, - int idx) + size_t idx) { return (struct json_object*)array_list_get_idx(jso->o.c_array, idx); } diff --git a/json_object.h b/json_object.h index 67137d8..f810678 100644 --- a/json_object.h +++ b/json_object.h @@ -449,7 +449,7 @@ extern struct array_list* json_object_get_array(struct json_object *obj); * @param obj the json_object instance * @returns an int */ -extern int json_object_array_length(struct json_object *obj); +extern size_t json_object_array_length(struct json_object *obj); /** Sorts the elements of jso of type json_type_array * @@ -507,7 +507,7 @@ extern int json_object_array_add(struct json_object *obj, * @param idx the index to insert the element at * @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); /** Get the element at specificed index of the array (a json_object of type json_type_array) @@ -516,7 +516,7 @@ extern int json_object_array_put_idx(struct json_object *obj, int idx, * @returns the json_object at the specified index (or NULL) */ extern struct json_object* json_object_array_get_idx(struct json_object *obj, - int idx); + size_t idx); /* json_bool type methods */