mirror of
https://github.com/json-c/json-c.git
synced 2026-03-21 22:19:07 +08:00
Use size_t for array list length and size
This commit is contained in:
12
arraylist.c
12
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;
|
||||
|
||||
10
arraylist.h
10
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
|
||||
|
||||
Reference in New Issue
Block a user