8000 cleanup: Remove our only use of flexible array members in toxcore. by iphydf · Pull Request #1910 · TokTok/c-toxcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cleanup: Remove our only use of flexible array members in toxcore. #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
01ff907eae6d12ec2fb597bc0d7bf2549aadf40a8b6bc608f0e910feabb97eec /usr/local/bin/tox-bootstrapd
8802a0afed0bcd3acaafebe22faf1f758935e3914d52472fc3e0c74e055fbc38 /usr/local/bin/tox-bootstrapd
2 changes: 1 addition & 1 deletion toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 13 additions & 4 deletions toxcore/TCP_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -69,6 +70,7 @@ int send_pending_data(TCP_Connection *con)

TCP_Priority_List *pp = p;
p = p->next;
free(pp->data);
free(pp);
}

Expand All @@ -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) {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
24 changes: 11 additions & 13 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down
0