mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
test: Upgrade cppcheck, fix some warnings.
Also started teaching it about toxcore's alloc/dealloc functions in hopes of it catching some errors (it doesn't seem to be very good at this, but maybe better than nothing?).
This commit is contained in:
parent
766e62bc89
commit
b7f9367f6f
|
@ -134,7 +134,6 @@ jobs:
|
|||
- run:
|
||||
apt-get install -y --no-install-recommends
|
||||
ca-certificates
|
||||
cppcheck
|
||||
g++
|
||||
llvm-dev
|
||||
- checkout
|
||||
|
@ -142,7 +141,6 @@ jobs:
|
|||
- run: other/analysis/check_includes
|
||||
- run: other/analysis/check_logger_levels
|
||||
- run: other/analysis/run-clang
|
||||
- run: other/analysis/run-cppcheck
|
||||
- run: other/analysis/run-gcc
|
||||
|
||||
clang-analyze:
|
||||
|
|
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
@ -13,6 +13,16 @@ jobs:
|
|||
common:
|
||||
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master
|
||||
|
||||
cppcheck:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Docker Build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
file: other/docker/cppcheck/Dockerfile
|
||||
|
||||
mypy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
@ -8,9 +8,12 @@ set -e
|
|||
|
||||
CPPCHECK=("--enable=all")
|
||||
CPPCHECK+=("--inconclusive")
|
||||
CPPCHECK+=("--check-level=exhaustive")
|
||||
CPPCHECK+=("--inline-suppr")
|
||||
CPPCHECK+=("--library=other/docker/cppcheck/toxcore.cfg")
|
||||
CPPCHECK+=("--error-exitcode=1")
|
||||
# Used for VLA.
|
||||
CPPCHECK+=("--suppress=allocaCalled")
|
||||
# We don't cast function pointers, which cppcheck suggests here.
|
||||
CPPCHECK+=("--suppress=constParameterCallback")
|
||||
# False positives in switch statements.
|
||||
CPPCHECK+=("--suppress=knownConditionTrueFalse")
|
||||
# Cppcheck does not need standard library headers to get proper results.
|
||||
|
@ -19,27 +22,22 @@ CPPCHECK+=("--suppress=missingIncludeSystem")
|
|||
CPPCHECK+=("--suppress=signConversion")
|
||||
# TODO(iphydf): Fixed in the toxav refactor PR.
|
||||
CPPCHECK+=("--suppress=redundantAssignment")
|
||||
# We have some redundant nullptr checks in assertions
|
||||
CPPCHECK+=("--suppress=nullPointerRedundantCheck")
|
||||
# Triggers a false warning in group.c
|
||||
CPPCHECK+=("--suppress=AssignmentAddressToInteger")
|
||||
# TODO(sudden6): This triggers a false positive, check again later to enable it
|
||||
CPPCHECK+=("--suppress=arrayIndexOutOfBoundsCond")
|
||||
|
||||
# We're a library. This only works on whole programs.
|
||||
CPPCHECK_C=("--suppress=unusedFunction")
|
||||
|
||||
# We use this for VLAs.
|
||||
CPPCHECK_CXX+=("--suppress=allocaCalled")
|
||||
# False positive in auto_tests.
|
||||
CPPCHECK_CXX+=("--suppress=shadowArgument")
|
||||
CPPCHECK_CXX+=("--suppress=shadowFunction")
|
||||
# False positive for callback functions
|
||||
CPPCHECK_CXX+=("--suppress=constParameter")
|
||||
# False positive in group.c.
|
||||
# Using cppcheck-suppress claims the suppression is unused.
|
||||
CPPCHECK_CXX+=("--suppress=AssignmentAddressToInteger")
|
||||
# We use C style casts because we write C code.
|
||||
CPPCHECK_CXX+=("--suppress=cstyleCast")
|
||||
# Used in Messenger.c for a static_assert(...)
|
||||
CPPCHECK_CXX+=("--suppress=sizeofFunctionCall")
|
||||
|
||||
run() {
|
||||
echo "Running cppcheck in variant '$*'"
|
||||
cppcheck "${CPPCHECK[@]}" "${CPPCHECK_C[@]}" tox*/*.[ch] tox*/*/*.[ch] "${CPPFLAGS[@]}" "$@"
|
||||
cppcheck -j8 "${CPPCHECK[@]}" "${CPPCHECK_C[@]}" tox*/*.[ch] tox*/*/*.[ch] "${CPPFLAGS[@]}" "$@"
|
||||
cppcheck "${CPPCHECK[@]}" "${CPPCHECK_CXX[@]}" amalgamation.cc "${CPPFLAGS[@]}" "$@"
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
f0bff9fe04d56543d95a457afd76c618139eef99a4302337c66d07759d108e8b /usr/local/bin/tox-bootstrapd
|
||||
68432689967d06dd144e5cdfe37751ccc62b2aa85b73a9cc55aff3732dc47fde /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -57,7 +57,7 @@ static void sleep_milliseconds(uint32_t ms)
|
|||
// returns 1 on success
|
||||
// 0 on failure - no keys were read or stored
|
||||
|
||||
static int manage_keys(DHT *dht, char *keys_file_path)
|
||||
static int manage_keys(DHT *dht, const char *keys_file_path)
|
||||
{
|
||||
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
|
||||
uint8_t keys[KEYS_SIZE];
|
||||
|
|
30
other/docker/cppcheck/Dockerfile
Normal file
30
other/docker/cppcheck/Dockerfile
Normal file
|
@ -0,0 +1,30 @@
|
|||
FROM alpine:3.19.0
|
||||
|
||||
RUN ["apk", "add", "--no-cache", \
|
||||
"bash", \
|
||||
"cppcheck", \
|
||||
"findutils", \
|
||||
"libconfig-dev", \
|
||||
"libsodium-dev", \
|
||||
"libvpx-dev", \
|
||||
"linux-headers", \
|
||||
"make", \
|
||||
"opus-dev"]
|
||||
|
||||
COPY other/bootstrap_daemon/ /src/workspace/c-toxcore/other/bootstrap_daemon/
|
||||
COPY other/bootstrap_node_packets.* /src/workspace/c-toxcore/other/
|
||||
COPY other/fun/ /src/workspace/c-toxcore/other/fun/
|
||||
COPY auto_tests/check_compat.h /src/workspace/c-toxcore/auto_tests/
|
||||
COPY testing/ /src/workspace/c-toxcore/testing/
|
||||
COPY toxav/ /src/workspace/c-toxcore/toxav/
|
||||
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
|
||||
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
|
||||
COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/
|
||||
COPY other/analysis/run-cppcheck \
|
||||
other/analysis/gen-file.sh \
|
||||
other/analysis/variants.sh \
|
||||
/src/workspace/c-toxcore/other/analysis/
|
||||
COPY other/docker/cppcheck/toxcore.cfg \
|
||||
/src/workspace/c-toxcore/other/docker/cppcheck/
|
||||
WORKDIR /src/workspace/c-toxcore
|
||||
RUN ["other/analysis/run-cppcheck"]
|
5
other/docker/cppcheck/run
Executable file
5
other/docker/cppcheck/run
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
BUILD=cppcheck
|
||||
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
117
other/docker/cppcheck/toxcore.cfg
Normal file
117
other/docker/cppcheck/toxcore.cfg
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0"?>
|
||||
<def format="2">
|
||||
<memory>
|
||||
<alloc init="false" buffer-size="malloc:2">mem_balloc</alloc>
|
||||
<alloc init="true" buffer-size="malloc:2">mem_alloc</alloc>
|
||||
<alloc init="true" buffer-size="calloc:2,3">mem_valloc</alloc>
|
||||
<realloc init="false" buffer-size="calloc:3,4">mem_vrealloc</realloc>
|
||||
<dealloc arg="2">mem_delete</dealloc>
|
||||
</memory>
|
||||
<resource>
|
||||
<alloc init="true">bin_pack_new</alloc>
|
||||
<dealloc arg="1">bin_pack_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">bin_unpack_new</alloc>
|
||||
<dealloc arg="1">bin_unpack_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">friendreq_new</alloc>
|
||||
<dealloc arg="1">friendreq_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">logger_new</alloc>
|
||||
<dealloc arg="1">logger_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">mono_time_new</alloc>
|
||||
<dealloc arg="1">mono_time_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">ping_array_new</alloc>
|
||||
<dealloc arg="1">ping_array_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">ping_new</alloc>
|
||||
<dealloc arg="1">ping_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">shared_key_cache_new</alloc>
|
||||
<dealloc arg="1">shared_key_cache_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_dispatch_new</alloc>
|
||||
<dealloc arg="1">tox_dispatch_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_new</alloc>
|
||||
<dealloc arg="1">tox_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_options_new</alloc>
|
||||
<dealloc arg="1">tox_options_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_announcements</alloc>
|
||||
<dealloc arg="1">kill_announcements</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_dht</alloc>
|
||||
<dealloc arg="1">kill_dht</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_dht_groupchats</alloc>
|
||||
<dealloc arg="1">kill_dht_groupchats</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_forwarding</alloc>
|
||||
<dealloc arg="1">kill_forwarding</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_friend_connections</alloc>
|
||||
<dealloc arg="1">kill_friend_connections</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_gca_list</alloc>
|
||||
<dealloc arg="1">kill_gca_list</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_groupchats</alloc>
|
||||
<dealloc arg="1">kill_groupchats</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_messenger</alloc>
|
||||
<dealloc arg="1">kill_messenger</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_net_crypto</alloc>
|
||||
<dealloc arg="1">kill_net_crypto</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_networking_ex</alloc>
|
||||
<alloc init="true">new_networking_no_udp</alloc>
|
||||
<dealloc arg="1">kill_networking</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion</alloc>
|
||||
<dealloc arg="1">kill_onion</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion_announce</alloc>
|
||||
<dealloc arg="1">kill_onion_announce</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion_client</alloc>
|
||||
<dealloc arg="1">kill_onion_client</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_tcp_connections</alloc>
|
||||
<dealloc arg="1">kill_tcp_connections</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_tcp_server</alloc>
|
||||
<dealloc arg="1">kill_tcp_server</dealloc>
|
||||
</resource>
|
||||
</def>
|
||||
<!-- vim:ft=xml
|
||||
-->
|
|
@ -41,7 +41,7 @@ static bool create_tox(const unsigned char *const secret_key, Tox **const tox)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool print_savedata(Tox *const tox)
|
||||
static bool print_savedata(const Tox *const tox)
|
||||
{
|
||||
const size_t savedata_size = tox_get_savedata_size(tox);
|
||||
uint8_t *const savedata = (uint8_t *)malloc(savedata_size);
|
||||
|
|
|
@ -61,7 +61,7 @@ static void tox_connection_callback(Tox *tox, Tox_Connection connection, void *u
|
|||
}
|
||||
}
|
||||
|
||||
static void print_information(Tox *tox)
|
||||
static void print_information(const Tox *tox)
|
||||
{
|
||||
uint8_t tox_id[TOX_ADDRESS_SIZE];
|
||||
char tox_id_str[TOX_ADDRESS_SIZE * 2];
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "../../testing/misc_tools.h" // hex_string_to_bin
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
static int load_file(char *filename, unsigned char **result)
|
||||
static int load_file(const char *filename, unsigned char **result)
|
||||
{
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
#define PRINT_TRIES_COUNT
|
||||
|
||||
static void print_key(unsigned char *key)
|
||||
static void print_key(const unsigned char *key)
|
||||
{
|
||||
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
|
||||
if (key[i] < 16) {
|
||||
|
@ -125,7 +125,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
} while (!found);
|
||||
} else {
|
||||
unsigned char *p = public_key + offset;
|
||||
const unsigned char *p = public_key + offset;
|
||||
|
||||
do {
|
||||
#ifdef PRINT_TRIES_COUNT
|
||||
|
|
|
@ -434,7 +434,7 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_
|
|||
}
|
||||
|
||||
while (decode_audio_packet((Group_AV *)object, peer_av, groupnumber, friendgroupnumber) == 0) {
|
||||
continue;
|
||||
/* Continue. */
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -612,7 +612,7 @@ static int send_audio_packet(const Group_Chats *g_c, uint32_t groupnumber, const
|
|||
* @retval 0 on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
||||
int group_send_audio(const Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
||||
uint32_t sample_rate)
|
||||
{
|
||||
Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber);
|
||||
|
|
|
@ -40,7 +40,7 @@ int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t fr
|
|||
* @retval 0 on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
||||
int group_send_audio(const Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
||||
uint32_t sample_rate);
|
||||
|
||||
/** @brief Enable A/V in a groupchat.
|
||||
|
|
|
@ -62,8 +62,8 @@ static void msg_init(MSIMessage *dest, MSIRequest request);
|
|||
static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length);
|
||||
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len,
|
||||
uint16_t *length);
|
||||
static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg);
|
||||
static int send_error(Messenger *m, uint32_t friend_number, MSIError error);
|
||||
static int send_message(const Messenger *m, uint32_t friend_number, const MSIMessage *msg);
|
||||
static int send_error(const Messenger *m, uint32_t friend_number, MSIError error);
|
||||
static bool invoke_callback(MSICall *call, MSICallbackID cb);
|
||||
static MSICall *get_call(MSISession *session, uint32_t friend_number);
|
||||
static MSICall *new_call(MSISession *session, uint32_t friend_number);
|
||||
|
@ -444,7 +444,7 @@ static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *
|
|||
|
||||
return dest + value_len; /* Set to next position ready to be written */
|
||||
}
|
||||
static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg)
|
||||
static int send_message(const Messenger *m, uint32_t friend_number, const MSIMessage *msg)
|
||||
{
|
||||
/* Parse and send message */
|
||||
assert(m != nullptr);
|
||||
|
@ -489,7 +489,7 @@ static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *
|
|||
|
||||
return -1;
|
||||
}
|
||||
static int send_error(Messenger *m, uint32_t friend_number, MSIError error)
|
||||
static int send_error(const Messenger *m, uint32_t friend_number, MSIError error)
|
||||
{
|
||||
/* Send error message */
|
||||
assert(m != nullptr);
|
||||
|
|
|
@ -1930,14 +1930,11 @@ static void do_close(DHT *dht)
|
|||
for (size_t i = 0; i < LCLIENT_LIST; ++i) {
|
||||
Client_data *const client = &dht->close_clientlist[i];
|
||||
|
||||
IPPTsPng *const assocs[] = { &client->assoc6, &client->assoc4, nullptr };
|
||||
|
||||
for (IPPTsPng * const *it = assocs; *it != nullptr; ++it) {
|
||||
IPPTsPng *const assoc = *it;
|
||||
|
||||
if (assoc->timestamp != 0) {
|
||||
assoc->timestamp = badonly;
|
||||
if (client->assoc4.timestamp != 0) {
|
||||
client->assoc4.timestamp = badonly;
|
||||
}
|
||||
if (client->assoc6.timestamp != 0) {
|
||||
client->assoc6.timestamp = badonly;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3183,7 +3183,7 @@ static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void
|
|||
non_null()
|
||||
static uint32_t saved_groups_size(const Messenger *m)
|
||||
{
|
||||
GC_Session *c = m->group_handler;
|
||||
const GC_Session *c = m->group_handler;
|
||||
return bin_pack_obj_size(pack_groupchats_handler, m->log, c);
|
||||
}
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ struct Messenger {
|
|||
m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
|
||||
void *friend_connectionstatuschange_internal_userdata;
|
||||
|
||||
struct Group_Chats *conferences_object; /* Set by new_groupchats()*/
|
||||
struct Group_Chats *conferences_object;
|
||||
m_conference_invite_cb *conference_invite;
|
||||
|
||||
m_group_invite_cb *group_invite;
|
||||
|
|
|
@ -118,9 +118,9 @@ static bool connect_sock_to(const Logger *logger, const Memory *mem, Socket sock
|
|||
non_null()
|
||||
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
|
||||
{
|
||||
char one[] = "CONNECT ";
|
||||
char two[] = " HTTP/1.1\nHost: ";
|
||||
char three[] = "\r\n\r\n";
|
||||
const char one[] = "CONNECT ";
|
||||
const char two[] = " HTTP/1.1\nHost: ";
|
||||
const char three[] = "\r\n\r\n";
|
||||
|
||||
char ip[TOX_INET6_ADDRSTRLEN];
|
||||
|
||||
|
@ -149,7 +149,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
|
|||
non_null()
|
||||
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
|
||||
{
|
||||
char success[] = "200";
|
||||
const char success[] = "200";
|
||||
uint8_t data[16]; // draining works the best if the length is a power of 2
|
||||
|
||||
const TCP_Connection *con0 = &tcp_conn->con;
|
||||
|
@ -912,8 +912,7 @@ static int do_confirmed_tcp(const Logger *logger, TCP_Client_Connection *conn, c
|
|||
}
|
||||
|
||||
while (tcp_process_packet(logger, conn, userdata)) {
|
||||
// Keep reading until error or out of data.
|
||||
continue;
|
||||
/* Keep reading until error or out of data. */
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -407,7 +407,7 @@ int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c)
|
|||
* return -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int get_conn_number_by_ip_port(TCP_Connections *tcp_c, const IP_Port *ip_port)
|
||||
static int get_conn_number_by_ip_port(const TCP_Connections *tcp_c, const IP_Port *ip_port)
|
||||
{
|
||||
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
|
||||
const IP_Port conn_ip_port = tcp_con_ip_port(tcp_c->tcp_connections[i].connection);
|
||||
|
@ -1059,7 +1059,7 @@ static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_
|
|||
non_null()
|
||||
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
|
||||
{
|
||||
TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object;
|
||||
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
|
||||
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);
|
||||
|
||||
const unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con);
|
||||
|
@ -1256,7 +1256,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
|
|||
bool sent_any = false;
|
||||
|
||||
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
|
||||
TCP_Connection_to *con_to = get_connection(tcp_c, i);
|
||||
const TCP_Connection_to *con_to = get_connection(tcp_c, i);
|
||||
|
||||
if (con_to != nullptr) {
|
||||
if (tcp_connection_in_conn(con_to, tcp_connections_number)) {
|
||||
|
|
|
@ -1144,8 +1144,7 @@ non_null()
|
|||
static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
|
||||
{
|
||||
while (tcp_process_secure_packet(tcp_server, i)) {
|
||||
// Keep reading until an error occurs or there is no more data to read.
|
||||
continue;
|
||||
/* Keep reading until an error occurs or there is no more data to read. */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -302,7 +302,7 @@ static int create_reply_plain_data_search_request(Announcements *announce,
|
|||
const IP_Port *source,
|
||||
const uint8_t *data, uint16_t length,
|
||||
uint8_t *reply, uint16_t reply_max_length,
|
||||
uint8_t *to_auth, uint16_t to_auth_length)
|
||||
const uint8_t *to_auth, uint16_t to_auth_length)
|
||||
{
|
||||
if (length != CRYPTO_PUBLIC_KEY_SIZE &&
|
||||
length != CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA256_SIZE) {
|
||||
|
@ -377,11 +377,12 @@ static int create_reply_plain_data_search_request(Announcements *announce,
|
|||
}
|
||||
|
||||
non_null()
|
||||
static int create_reply_plain_data_retrieve_request(Announcements *announce,
|
||||
static int create_reply_plain_data_retrieve_request(
|
||||
const Announcements *announce,
|
||||
const IP_Port *source,
|
||||
const uint8_t *data, uint16_t length,
|
||||
uint8_t *reply, uint16_t reply_max_length,
|
||||
uint8_t *to_auth, uint16_t to_auth_length)
|
||||
const uint8_t *to_auth, uint16_t to_auth_length)
|
||||
{
|
||||
if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) {
|
||||
return -1;
|
||||
|
@ -423,7 +424,7 @@ static int create_reply_plain_store_announce_request(Announcements *announce,
|
|||
const IP_Port *source,
|
||||
const uint8_t *data, uint16_t length,
|
||||
uint8_t *reply, uint16_t reply_max_length,
|
||||
uint8_t *to_auth, uint16_t to_auth_length)
|
||||
const uint8_t *to_auth, uint16_t to_auth_length)
|
||||
{
|
||||
const int plain_len = (int)length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
|
||||
const int announcement_len = (int)plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1);
|
||||
|
|
|
@ -31,14 +31,14 @@ struct Forwarding {
|
|||
void *forwarded_response_callback_object;
|
||||
};
|
||||
|
||||
DHT *forwarding_get_dht(Forwarding *forwarding)
|
||||
DHT *forwarding_get_dht(const Forwarding *forwarding)
|
||||
{
|
||||
return forwarding->dht;
|
||||
}
|
||||
|
||||
#define SENDBACK_TIMEOUT 3600
|
||||
|
||||
bool send_forward_request(Networking_Core *net, const IP_Port *forwarder,
|
||||
bool send_forward_request(const Networking_Core *net, const IP_Port *forwarder,
|
||||
const uint8_t *chain_keys, uint16_t chain_length,
|
||||
const uint8_t *data, uint16_t data_length)
|
||||
{
|
||||
|
@ -316,7 +316,7 @@ static int handle_forwarding(void *object, const IP_Port *source, const uint8_t
|
|||
}
|
||||
}
|
||||
|
||||
bool forward_reply(Networking_Core *net, const IP_Port *forwarder,
|
||||
bool forward_reply(const Networking_Core *net, const IP_Port *forwarder,
|
||||
const uint8_t *sendback, uint16_t sendback_length,
|
||||
const uint8_t *data, uint16_t length)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
typedef struct Forwarding Forwarding;
|
||||
|
||||
non_null()
|
||||
DHT *forwarding_get_dht(Forwarding *forwarding);
|
||||
DHT *forwarding_get_dht(const Forwarding *forwarding);
|
||||
|
||||
/**
|
||||
* @brief Send data to forwarder for forwarding via chain of dht nodes.
|
||||
|
@ -41,7 +41,7 @@ DHT *forwarding_get_dht(Forwarding *forwarding);
|
|||
* @return true on success, false otherwise.
|
||||
*/
|
||||
non_null()
|
||||
bool send_forward_request(Networking_Core *net, const IP_Port *forwarder,
|
||||
bool send_forward_request(const Networking_Core *net, const IP_Port *forwarder,
|
||||
const uint8_t *chain_keys, uint16_t chain_length,
|
||||
const uint8_t *data, uint16_t data_length);
|
||||
|
||||
|
@ -75,7 +75,7 @@ bool create_forward_chain_packet(const uint8_t *chain_keys, uint16_t chain_lengt
|
|||
* @return true on success, false otherwise.
|
||||
*/
|
||||
non_null()
|
||||
bool forward_reply(Networking_Core *net, const IP_Port *forwarder,
|
||||
bool forward_reply(const Networking_Core *net, const IP_Port *forwarder,
|
||||
const uint8_t *sendback, uint16_t sendback_length,
|
||||
const uint8_t *data, uint16_t length);
|
||||
|
||||
|
|
|
@ -212,13 +212,13 @@ static bool group_id_eq(const uint8_t *a, const uint8_t *b)
|
|||
}
|
||||
|
||||
non_null()
|
||||
static bool g_title_eq(Group_c *g, const uint8_t *title, uint8_t title_len)
|
||||
static bool g_title_eq(const Group_c *g, const uint8_t *title, uint8_t title_len)
|
||||
{
|
||||
return memeq(g->title, g->title_len, title, title_len);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool g_peer_nick_eq(Group_Peer *peer, const uint8_t *nick, uint8_t nick_len)
|
||||
static bool g_peer_nick_eq(const Group_Peer *peer, const uint8_t *nick, uint8_t nick_len)
|
||||
{
|
||||
return memeq(peer->nick, peer->nick_len, nick, nick_len);
|
||||
}
|
||||
|
@ -3767,7 +3767,6 @@ Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m)
|
|||
temp->mono_time = mono_time;
|
||||
temp->m = m;
|
||||
temp->fr_c = m->fr_c;
|
||||
m->conferences_object = temp;
|
||||
m_callback_conference_invite(m, &handle_friend_invite_packet);
|
||||
|
||||
set_global_status_callback(m->fr_c, &g_handle_any_status, temp);
|
||||
|
|
|
@ -156,7 +156,7 @@ non_null() static bool self_gc_is_founder(const GC_Chat *chat);
|
|||
non_null() static bool group_number_valid(const GC_Session *c, int group_number);
|
||||
non_null() static int peer_update(const GC_Chat *chat, const GC_Peer *peer, uint32_t peer_number);
|
||||
non_null() static void group_delete(GC_Session *c, GC_Chat *chat);
|
||||
non_null() static void group_cleanup(GC_Session *c, GC_Chat *chat);
|
||||
non_null() static void group_cleanup(const GC_Session *c, GC_Chat *chat);
|
||||
non_null() static bool group_exists(const GC_Session *c, const uint8_t *chat_id);
|
||||
non_null() static void add_tcp_relays_to_chat(const GC_Session *c, GC_Chat *chat);
|
||||
non_null(1, 2) nullable(4)
|
||||
|
@ -8178,7 +8178,7 @@ GC_Session *new_dht_groupchats(Messenger *m)
|
|||
return c;
|
||||
}
|
||||
|
||||
static void group_cleanup(GC_Session *c, GC_Chat *chat)
|
||||
static void group_cleanup(const GC_Session *c, GC_Chat *chat)
|
||||
{
|
||||
kill_group_friend_connection(c, chat);
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon
|
|||
const uint16_t end_idx = gcc_get_array_index(gconn->send_message_id);
|
||||
|
||||
for (uint16_t i = start_idx; i != end_idx; i = (i + 1) % GCC_BUFFER_SIZE) {
|
||||
GC_Message_Array_Entry *entry = &gconn->send_array[i];
|
||||
const GC_Message_Array_Entry *entry = &gconn->send_array[i];
|
||||
|
||||
if (array_entry_is_empty(entry)) {
|
||||
LOGGER_FATAL(chat->log, "array entry for packet chunk is empty");
|
||||
|
|
|
@ -219,10 +219,9 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uin
|
|||
uint64_t number, uint8_t *shared_key)
|
||||
{
|
||||
uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH];
|
||||
uint8_t padding[CRYPTO_PUBLIC_KEY_SIZE] = {0};
|
||||
|
||||
memcpy(plain, c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, padding, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memset(plain + CRYPTO_PUBLIC_KEY_SIZE, 0, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(plain + (CRYPTO_PUBLIC_KEY_SIZE * 2), &number, sizeof(uint64_t));
|
||||
const uint8_t *tmp_shared_key = dht_get_shared_key_sent(c->dht, dht_public_key);
|
||||
memcpy(shared_key, tmp_shared_key, CRYPTO_SHARED_KEY_SIZE);
|
||||
|
|
|
@ -735,6 +735,7 @@ Onion *new_onion(const Logger *log, const Memory *mem, const Mono_Time *mono_tim
|
|||
if (onion->shared_keys_1 == nullptr ||
|
||||
onion->shared_keys_2 == nullptr ||
|
||||
onion->shared_keys_3 == nullptr) {
|
||||
// cppcheck-suppress mismatchAllocDealloc
|
||||
kill_onion(onion);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -669,6 +669,7 @@ Onion_Announce *new_onion_announce(const Logger *log, const Memory *mem, const R
|
|||
|
||||
onion_a->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht_get_self_secret_key(dht), KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
if (onion_a->shared_keys_recv == nullptr) {
|
||||
// cppcheck-suppress mismatchAllocDealloc
|
||||
kill_onion_announce(onion_a);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -841,7 +841,9 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (new_groupchats(tox->mono_time, tox->m) == nullptr) {
|
||||
tox->m->conferences_object = new_groupchats(tox->mono_time, tox->m);
|
||||
|
||||
if (tox->m->conferences_object == nullptr) {
|
||||
kill_messenger(tox->m);
|
||||
|
||||
mono_time_free(tox->sys.mem, tox->mono_time);
|
||||
|
@ -2723,6 +2725,7 @@ static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error
|
|||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress constParameterPointer
|
||||
bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
|
||||
Tox_Err_Friend_Custom_Packet *error)
|
||||
{
|
||||
|
@ -2762,6 +2765,7 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call
|
|||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress constParameterPointer
|
||||
bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
|
||||
Tox_Err_Friend_Custom_Packet *error)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user