Fixed another thing in loop; added initialization for tox_array in lossless UDP.

This commit is contained in:
Anony Moose 2013-08-28 22:04:34 +00:00
parent 82a3eb9763
commit 31354d80d4
2 changed files with 5 additions and 8 deletions

View File

@ -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

View File

@ -696,10 +696,11 @@ Lossless_UDP *new_lossless_udp(Networking_Core *net)
return NULL;
Lossless_UDP *temp = calloc(1, sizeof(Lossless_UDP));
if (temp == NULL)
return NULL;
tox_array_init(&temp->connections, sizeof(Connection));
temp->net = net;
networking_registerhandler(net, NET_PACKET_HANDSHAKE, &handle_handshake, temp);
networking_registerhandler(net, NET_PACKET_SYNC, &handle_SYNC, temp);