summaryrefslogtreecommitdiff
path: root/testing/misc_tools.h
diff options
context:
space:
mode:
authorAnony Moose <noMail@nomail.su>2013-08-28 22:04:34 +0000
committerAnony Moose <noMail@nomail.su>2013-08-28 22:04:34 +0000
commit31354d80d40270ee415b84e312f91b47bf104afe (patch)
tree8e880ef5ac30a841fc5c0495122b0e91a3317f22 /testing/misc_tools.h
parent82a3eb9763953d39f7ddafc40fe71b1d4cc13dbf (diff)
Fixed another thing in loop; added initialization for tox_array in lossless UDP.
Diffstat (limited to 'testing/misc_tools.h')
-rw-r--r--testing/misc_tools.h10
1 files changed, 3 insertions, 7 deletions
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)
117 ************************************************************/ 117 ************************************************************/
118 118
119typedef struct tox_array { 119typedef struct tox_array {
120 void *data; /* last elem is data[len-1] */ 120 uint8_t *data; /* last elem is data[len-1] */
121 uint32_t len; 121 uint32_t len;
122 size_t elem_size; /* in bytes */ 122 size_t elem_size; /* in bytes */
123} tox_array; 123} tox_array;
@@ -138,10 +138,6 @@ static inline void tox_array_delete(tox_array *arr)
138static inline uint8_t tox_array_push_ptr(tox_array *arr, uint8_t *item) 138static inline uint8_t tox_array_push_ptr(tox_array *arr, uint8_t *item)
139{ 139{
140 arr->data = realloc(arr->data, arr->elem_size * (arr->len+1)); 140 arr->data = realloc(arr->data, arr->elem_size * (arr->len+1));
141
142 if (arr->data == NULL) /* didn't call tox_array_init() */
143 return 0;
144
145 if (item != NULL) 141 if (item != NULL)
146 memcpy(arr->data + arr->elem_size*arr->len, item, arr->elem_size); 142 memcpy(arr->data + arr->elem_size*arr->len, item, arr->elem_size);
147 arr->len++; 143 arr->len++;
@@ -166,7 +162,7 @@ static inline void tox_array_pop(tox_array *arr, uint32_t num)
166 162
167 163
168#define tox_array_for_each(arr, type, tmp_name) \ 164#define tox_array_for_each(arr, type, tmp_name) \
169 type *tmp_name; uint32_t tmp_name ## _i = 0; \ 165 type *tmp_name = &tox_array_get(arr, 0, type); uint32_t tmp_name ## _i = 0; \
170 for (; tmp_name ## _i != (arr)->len; tmp_name = &tox_array_get(arr, ++ tmp_name ## _i, type)) 166 for (; tmp_name ## _i < (arr)->len; tmp_name = &tox_array_get(arr, ++ tmp_name ## _i, type))
171 167
172#endif // MISC_TOOLS_H 168#endif // MISC_TOOLS_H