diff options
-rw-r--r-- | testing/misc_tools.h | 10 | ||||
-rw-r--r-- | toxcore/Lossless_UDP.c | 3 |
2 files changed, 5 insertions, 8 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 | ||
119 | typedef struct tox_array { | 119 | typedef 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) | |||
138 | static inline uint8_t tox_array_push_ptr(tox_array *arr, uint8_t *item) | 138 | static 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 |
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c index 63f3bd16..f360bcbb 100644 --- a/toxcore/Lossless_UDP.c +++ b/toxcore/Lossless_UDP.c | |||
@@ -696,10 +696,11 @@ Lossless_UDP *new_lossless_udp(Networking_Core *net) | |||
696 | return NULL; | 696 | return NULL; |
697 | 697 | ||
698 | Lossless_UDP *temp = calloc(1, sizeof(Lossless_UDP)); | 698 | Lossless_UDP *temp = calloc(1, sizeof(Lossless_UDP)); |
699 | |||
700 | if (temp == NULL) | 699 | if (temp == NULL) |
701 | return NULL; | 700 | return NULL; |
702 | 701 | ||
702 | tox_array_init(&temp->connections, sizeof(Connection)); | ||
703 | |||
703 | temp->net = net; | 704 | temp->net = net; |
704 | networking_registerhandler(net, NET_PACKET_HANDSHAKE, &handle_handshake, temp); | 705 | networking_registerhandler(net, NET_PACKET_HANDSHAKE, &handle_handshake, temp); |
705 | networking_registerhandler(net, NET_PACKET_SYNC, &handle_SYNC, temp); | 706 | networking_registerhandler(net, NET_PACKET_SYNC, &handle_SYNC, temp); |