mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed another thing in loop; added initialization for tox_array in lossless UDP.
This commit is contained in:
parent
82a3eb9763
commit
31354d80d4
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user