mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed some non standard C.
Replaced void * with uint8_t * in list.c
This commit is contained in:
parent
b2c966a6e3
commit
7d13f1928e
|
@ -45,7 +45,7 @@
|
|||
* < 0 : no match, returns index (return value is INDEX(index)) where
|
||||
* the data should be inserted
|
||||
*/
|
||||
static int find(const BS_LIST *list, const void *data)
|
||||
static int find(const BS_LIST *list, const uint8_t *data)
|
||||
{
|
||||
//should work well, but could be improved
|
||||
if (list->n == 0) {
|
||||
|
@ -113,7 +113,7 @@ static int find(const BS_LIST *list, const void *data)
|
|||
*/
|
||||
static int resize(BS_LIST *list, uint32_t new_size)
|
||||
{
|
||||
void *p;
|
||||
uint8_t *p;
|
||||
|
||||
p = realloc(list->data, list->element_size * new_size);
|
||||
|
||||
|
@ -162,7 +162,7 @@ void bs_list_free(BS_LIST *list)
|
|||
free(list->ids);
|
||||
}
|
||||
|
||||
int bs_list_find(const BS_LIST *list, const void *data)
|
||||
int bs_list_find(const BS_LIST *list, const uint8_t *data)
|
||||
{
|
||||
int r = find(list, data);
|
||||
|
||||
|
@ -174,7 +174,7 @@ int bs_list_find(const BS_LIST *list, const void *data)
|
|||
return list->ids[r];
|
||||
}
|
||||
|
||||
int bs_list_add(BS_LIST *list, const void *data, int id)
|
||||
int bs_list_add(BS_LIST *list, const uint8_t *data, int id)
|
||||
{
|
||||
//find where the new element should be inserted
|
||||
//see: return value of find()
|
||||
|
@ -214,7 +214,7 @@ int bs_list_add(BS_LIST *list, const void *data, int id)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int bs_list_remove(BS_LIST *list, const void *data, int id)
|
||||
int bs_list_remove(BS_LIST *list, const uint8_t *data, int id)
|
||||
{
|
||||
int i = find(list, data);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef struct {
|
|||
uint32_t n; //number of elements
|
||||
uint32_t capacity; //number of elements memory is allocated for
|
||||
uint32_t element_size; //size of the elements
|
||||
void *data; //array of elements
|
||||
uint8_t *data; //array of elements
|
||||
int *ids; //array of element ids
|
||||
} BS_LIST;
|
||||
|
||||
|
@ -56,7 +56,7 @@ void bs_list_free(BS_LIST *list);
|
|||
* >= 0 : id associated with data
|
||||
* -1 : failure
|
||||
*/
|
||||
int bs_list_find(const BS_LIST *list, const void *data);
|
||||
int bs_list_find(const BS_LIST *list, const uint8_t *data);
|
||||
|
||||
/* Add an element with associated id to the list
|
||||
*
|
||||
|
@ -64,7 +64,7 @@ int bs_list_find(const BS_LIST *list, const void *data);
|
|||
* 1 : success
|
||||
* 0 : failure (data already in list)
|
||||
*/
|
||||
int bs_list_add(BS_LIST *list, const void *data, int id);
|
||||
int bs_list_add(BS_LIST *list, const uint8_t *data, int id);
|
||||
|
||||
/* Remove element from the list
|
||||
*
|
||||
|
@ -72,7 +72,7 @@ int bs_list_add(BS_LIST *list, const void *data, int id);
|
|||
* 1 : success
|
||||
* 0 : failure (element not found or id does not match)
|
||||
*/
|
||||
int bs_list_remove(BS_LIST *list, const void *data, int id);
|
||||
int bs_list_remove(BS_LIST *list, const uint8_t *data, int id);
|
||||
|
||||
/* Removes the memory overhead
|
||||
*
|
||||
|
|
|
@ -1439,10 +1439,10 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
|
|||
|
||||
if (source.ip.family == AF_INET || source.ip.family == AF_INET6) {
|
||||
if (!ipport_equal(&source, &conn->ip_port)) {
|
||||
if (!bs_list_add(&c->ip_port_list, &source, crypt_connection_id))
|
||||
if (!bs_list_add(&c->ip_port_list, (uint8_t *)&source, crypt_connection_id))
|
||||
return -1;
|
||||
|
||||
bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id);
|
||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
|
||||
conn->ip_port = source;
|
||||
}
|
||||
|
||||
|
@ -1658,8 +1658,8 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (bs_list_add(&c->ip_port_list, &ip_port, crypt_connection_id)) {
|
||||
bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id);
|
||||
if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
|
||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
|
||||
conn->ip_port = ip_port;
|
||||
conn->direct_lastrecv_time = 0;
|
||||
return 0;
|
||||
|
@ -1933,7 +1933,7 @@ int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(
|
|||
*/
|
||||
static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port)
|
||||
{
|
||||
return bs_list_find(&c->ip_port_list, &ip_port);
|
||||
return bs_list_find(&c->ip_port_list, (uint8_t *)&ip_port);
|
||||
}
|
||||
|
||||
#define CRYPTO_MIN_PACKET_SIZE (1 + sizeof(uint16_t) + crypto_box_MACBYTES)
|
||||
|
@ -2282,7 +2282,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
|
|||
kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id);
|
||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
|
||||
clear_temp_packet(c, crypt_connection_id);
|
||||
clear_buffer(&conn->send_array);
|
||||
clear_buffer(&conn->recv_array);
|
||||
|
|
Loading…
Reference in New Issue
Block a user