mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
cleanup: Remove our only use of flexible array members in toxcore.
We still have them in toxav. That will need to be cleaned up later. Flexible array members have very limited usefulness. In this particular case, it's almost entirely useless. It confuses static analysers and is yet one more C feature we need to understand and support. It is also the only reason we need special support in tokstyle for calloc with a `+` operator in the member size.
This commit is contained in:
parent
5fbcbb6c83
commit
9dfad80017
|
@ -1 +1 @@
|
|||
01ff907eae6d12ec2fb597bc0d7bf2549aadf40a8b6bc608f0e910feabb97eec /usr/local/bin/tox-bootstrapd
|
||||
8802a0afed0bcd3acaafebe22faf1f758935e3914d52472fc3e0c74e055fbc38 /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -1614,7 +1614,7 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
DHT_Friend *const frnd = &dht->friends_list[friend_index];
|
||||
const DHT_Friend *const frnd = &dht->friends_list[friend_index];
|
||||
const uint32_t client_index = index_of_client_pk(frnd->client_list, MAX_FRIEND_CLIENTS, public_key);
|
||||
|
||||
if (client_index == -1) {
|
||||
|
|
|
@ -13,6 +13,7 @@ void wipe_priority_list(TCP_Priority_List *p)
|
|||
while (p) {
|
||||
TCP_Priority_List *pp = p;
|
||||
p = p->next;
|
||||
free(pp->data);
|
||||
free(pp);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +70,7 @@ int send_pending_data(TCP_Connection *con)
|
|||
|
||||
TCP_Priority_List *pp = p;
|
||||
p = p->next;
|
||||
free(pp->data);
|
||||
free(pp);
|
||||
}
|
||||
|
||||
|
@ -88,15 +90,22 @@ int send_pending_data(TCP_Connection *con)
|
|||
bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
|
||||
{
|
||||
TCP_Priority_List *p = con->priority_queue_end;
|
||||
TCP_Priority_List *new_list = (TCP_Priority_List *)calloc(1, sizeof(TCP_Priority_List) + size);
|
||||
TCP_Priority_List *new_list = (TCP_Priority_List *)calloc(1, sizeof(TCP_Priority_List));
|
||||
|
||||
if (!new_list) {
|
||||
return 0;
|
||||
if (new_list == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
new_list->next = nullptr;
|
||||
new_list->size = size;
|
||||
new_list->sent = sent;
|
||||
new_list->data = (uint8_t *)malloc(size);
|
||||
|
||||
if (new_list->data == nullptr) {
|
||||
free(new_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(new_list->data, packet, size);
|
||||
|
||||
if (p) {
|
||||
|
@ -106,7 +115,7 @@ bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uin
|
|||
}
|
||||
|
||||
con->priority_queue_end = new_list;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** return 1 on success.
|
||||
|
|
|
@ -14,7 +14,7 @@ struct TCP_Priority_List {
|
|||
TCP_Priority_List *next;
|
||||
uint16_t size;
|
||||
uint16_t sent;
|
||||
uint8_t data[];
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
void wipe_priority_list(TCP_Priority_List *p);
|
||||
|
|
|
@ -191,9 +191,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
|
|||
|
||||
index = tcp_server->num_accepted_connections;
|
||||
} else {
|
||||
uint32_t i;
|
||||
|
||||
for (i = tcp_server->size_accepted_connections; i != 0; --i) {
|
||||
for (uint32_t i = tcp_server->size_accepted_connections; i != 0; --i) {
|
||||
if (tcp_server->accepted_connection_array[i - 1].status == TCP_STATUS_NO_STATUS) {
|
||||
index = i - 1;
|
||||
break;
|
||||
|
|
|
@ -1069,7 +1069,7 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g,
|
|||
return ind;
|
||||
}
|
||||
|
||||
static unsigned int send_peer_introduced(Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
||||
static unsigned int send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
||||
|
||||
/** Removes reason for keeping connection.
|
||||
*
|
||||
|
@ -1483,7 +1483,7 @@ static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk
|
|||
return true;
|
||||
}
|
||||
|
||||
static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
||||
static unsigned int send_peer_query(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
||||
|
||||
static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t friendnumber, const uint8_t *data,
|
||||
uint16_t length);
|
||||
|
@ -2168,7 +2168,7 @@ static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_
|
|||
/** return 1 on success.
|
||||
* return 0 on failure
|
||||
*/
|
||||
static unsigned int send_peer_introduced(Group_Chats *g_c, int friendcon_id, uint16_t group_num)
|
||||
static unsigned int send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint16_t group_num)
|
||||
{
|
||||
uint8_t packet[1];
|
||||
packet[0] = PEER_INTRODUCED_ID;
|
||||
|
@ -2179,7 +2179,7 @@ static unsigned int send_peer_introduced(Group_Chats *g_c, int friendcon_id, uin
|
|||
/** return 1 on success.
|
||||
* return 0 on failure
|
||||
*/
|
||||
static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num)
|
||||
static unsigned int send_peer_query(const Group_Chats *g_c, int friendcon_id, uint16_t group_num)
|
||||
{
|
||||
uint8_t packet[1];
|
||||
packet[0] = PEER_QUERY_ID;
|
||||
|
@ -2189,7 +2189,7 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t
|
|||
/** return number of peers sent on success.
|
||||
* return 0 on failure.
|
||||
*/
|
||||
static unsigned int send_peers(Group_Chats *g_c, const Group_c *g, int friendcon_id, uint16_t group_num)
|
||||
static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int friendcon_id, uint16_t group_num)
|
||||
{
|
||||
uint8_t response_packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))];
|
||||
response_packet[0] = PEER_RESPONSE_ID;
|
||||
|
|
|
@ -988,9 +988,8 @@ Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from,
|
|||
*/
|
||||
uint16_t port_to_try = port_from;
|
||||
*portptr = net_htons(port_to_try);
|
||||
int tries;
|
||||
|
||||
for (tries = port_from; tries <= port_to; ++tries) {
|
||||
for (uint16_t tries = port_from; tries <= port_to; ++tries) {
|
||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
int res = 0;
|
||||
#else
|
||||
|
@ -1313,13 +1312,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
Family tox_family = to->family;
|
||||
int family = make_family(tox_family);
|
||||
|
||||
struct addrinfo *server = nullptr;
|
||||
struct addrinfo *walker = nullptr;
|
||||
struct addrinfo hints;
|
||||
int rc;
|
||||
int result = 0;
|
||||
int done = 0;
|
||||
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = family;
|
||||
hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
|
||||
|
@ -1328,7 +1321,9 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
return 0;
|
||||
}
|
||||
|
||||
rc = getaddrinfo(address, nullptr, &hints, &server);
|
||||
struct addrinfo *server = nullptr;
|
||||
|
||||
const int rc = getaddrinfo(address, nullptr, &hints, &server);
|
||||
|
||||
// Lookup failed.
|
||||
if (rc != 0) {
|
||||
|
@ -1340,14 +1335,17 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
IP ip6;
|
||||
ip_init(&ip6, 1); // ipv6enabled = 1
|
||||
|
||||
for (walker = server; (walker != nullptr) && !done; walker = walker->ai_next) {
|
||||
int result = 0;
|
||||
bool done = false;
|
||||
|
||||
for (struct addrinfo *walker = server; walker != nullptr && !done; walker = walker->ai_next) {
|
||||
switch (walker->ai_family) {
|
||||
case AF_INET: {
|
||||
if (walker->ai_family == family) { /* AF_INET requested, done */
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *)(void *)walker->ai_addr;
|
||||
get_ip4(&to->ip.v4, &addr->sin_addr);
|
||||
result = TOX_ADDR_RESOLVE_INET;
|
||||
done = 1;
|
||||
done = true;
|
||||
} else if (!(result & TOX_ADDR_RESOLVE_INET)) { /* AF_UNSPEC requested, store away */
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *)(void *)walker->ai_addr;
|
||||
get_ip4(&ip4.ip.v4, &addr->sin_addr);
|
||||
|
@ -1363,7 +1361,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)(void *)walker->ai_addr;
|
||||
get_ip6(&to->ip.v6, &addr->sin6_addr);
|
||||
result = TOX_ADDR_RESOLVE_INET6;
|
||||
done = 1;
|
||||
done = true;
|
||||
}
|
||||
} else if (!(result & TOX_ADDR_RESOLVE_INET6)) { /* AF_UNSPEC requested, store away */
|
||||
if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user