From 31354d80d40270ee415b84e312f91b47bf104afe Mon Sep 17 00:00:00 2001 From: Anony Moose Date: Wed, 28 Aug 2013 22:04:34 +0000 Subject: Fixed another thing in loop; added initialization for tox_array in lossless UDP. --- testing/misc_tools.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'testing/misc_tools.h') diff --git a/testing/misc_tools.h b/testing/misc_tools.h index 2d8707ed..f71d0064 100644 --- a/testing/misc_tools.h +++ b/testing/misc_tools.h @@ -117,7 +117,7 @@ static inline void tox_list_remove(tox_list *lst) ************************************************************/ typedef struct tox_array { - void *data; /* last elem is data[len-1] */ + uint8_t *data; /* last elem is data[len-1] */ uint32_t len; size_t elem_size; /* in bytes */ } tox_array; @@ -138,10 +138,6 @@ static inline void tox_array_delete(tox_array *arr) static inline uint8_t tox_array_push_ptr(tox_array *arr, uint8_t *item) { arr->data = realloc(arr->data, arr->elem_size * (arr->len+1)); - - if (arr->data == NULL) /* didn't call tox_array_init() */ - return 0; - if (item != NULL) memcpy(arr->data + arr->elem_size*arr->len, item, arr->elem_size); arr->len++; @@ -166,7 +162,7 @@ static inline void tox_array_pop(tox_array *arr, uint32_t num) #define tox_array_for_each(arr, type, tmp_name) \ - type *tmp_name; uint32_t tmp_name ## _i = 0; \ - for (; tmp_name ## _i != (arr)->len; tmp_name = &tox_array_get(arr, ++ tmp_name ## _i, type)) + type *tmp_name = &tox_array_get(arr, 0, type); uint32_t tmp_name ## _i = 0; \ + for (; tmp_name ## _i < (arr)->len; tmp_name = &tox_array_get(arr, ++ tmp_name ## _i, type)) #endif // MISC_TOOLS_H -- cgit v1.2.3