diff --git a/.circleci/config.yml b/.circleci/config.yml index ee37ea56fd..9006f68142 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39723e9089..ea641dbb2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck index c269c4e188..9dc6f17967 100755 --- a/other/analysis/run-cppcheck +++ b/other/analysis/run-cppcheck @@ -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[@]}" "$@" } diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 4c9830dc38..65acdd985b 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -f0bff9fe04d56543d95a457afd76c618139eef99a4302337c66d07759d108e8b /usr/local/bin/tox-bootstrapd +68432689967d06dd144e5cdfe37751ccc62b2aa85b73a9cc55aff3732dc47fde /usr/local/bin/tox-bootstrapd diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 5227db7815..9330e8ce8f 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -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]; diff --git a/other/docker/cppcheck/Dockerfile b/other/docker/cppcheck/Dockerfile new file mode 100644 index 0000000000..34b516fb48 --- /dev/null +++ b/other/docker/cppcheck/Dockerfile @@ -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"] diff --git a/other/docker/cppcheck/run b/other/docker/cppcheck/run new file mode 100755 index 0000000000..8e437f4cb5 --- /dev/null +++ b/other/docker/cppcheck/run @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux +BUILD=cppcheck +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/cppcheck/toxcore.cfg b/other/docker/cppcheck/toxcore.cfg new file mode 100644 index 0000000000..f120246a5f --- /dev/null +++ b/other/docker/cppcheck/toxcore.cfg @@ -0,0 +1,117 @@ + + + + mem_balloc + mem_alloc + mem_valloc + mem_vrealloc + mem_delete + + + bin_pack_new + bin_pack_free + + + bin_unpack_new + bin_unpack_free + + + friendreq_new + friendreq_kill + + + logger_new + logger_kill + + + mono_time_new + mono_time_free + + + ping_array_new + ping_array_kill + + + ping_new + ping_kill + + + shared_key_cache_new + shared_key_cache_free + + + tox_dispatch_new + tox_dispatch_free + + + tox_new + tox_kill + + + tox_options_new + tox_options_free + + + new_announcements + kill_announcements + + + new_dht + kill_dht + + + new_dht_groupchats + kill_dht_groupchats + + + new_forwarding + kill_forwarding + + + new_friend_connections + kill_friend_connections + + + new_gca_list + kill_gca_list + + + new_groupchats + kill_groupchats + + + new_messenger + kill_messenger + + + new_net_crypto + kill_net_crypto + + + new_networking_ex + new_networking_no_udp + kill_networking + + + new_onion + kill_onion + + + new_onion_announce + kill_onion_announce + + + new_onion_client + kill_onion_client + + + new_tcp_connections + kill_tcp_connections + + + new_tcp_server + kill_tcp_server + + + diff --git a/other/fun/create_savedata.c b/other/fun/create_savedata.c index 8a30525cc7..8456940239 100644 --- a/other/fun/create_savedata.c +++ b/other/fun/create_savedata.c @@ -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); diff --git a/other/fun/save-generator.c b/other/fun/save-generator.c index 6f65a9590b..9eb556899a 100644 --- a/other/fun/save-generator.c +++ b/other/fun/save-generator.c @@ -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]; diff --git a/other/fun/sign.c b/other/fun/sign.c index f6dcc71e82..a75fa0d4d0 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -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"); diff --git a/other/fun/strkey.c b/other/fun/strkey.c index 6440501413..538f59ade4 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c @@ -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 diff --git a/toxav/groupav.c b/toxav/groupav.c index 4e3ad2cc49..6a48c6845e 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c @@ -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); diff --git a/toxav/groupav.h b/toxav/groupav.h index a2801535d0..e85bc5f252 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h @@ -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. diff --git a/toxav/msi.c b/toxav/msi.c index e243884a00..2b45e7cbc7 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -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); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 9a418039ad..66a16600c4 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -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; } } } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c2752cde33..03872cc665 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -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); } diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index cabb2af89d..0ea88d704f 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -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; diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index df204406c0..a698eca862 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -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; diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index f274376c1c..c6118cdd48 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -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)) { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 905d2bb434..c07b176a12 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -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. */ } } diff --git a/toxcore/announce.c b/toxcore/announce.c index 402d1136de..5ac4986740 100644 --- a/toxcore/announce.c +++ b/toxcore/announce.c @@ -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); diff --git a/toxcore/forwarding.c b/toxcore/forwarding.c index 5e885abd21..be96a21dbf 100644 --- a/toxcore/forwarding.c +++ b/toxcore/forwarding.c @@ -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) { diff --git a/toxcore/forwarding.h b/toxcore/forwarding.h index 36ce8ad894..a97971e637 100644 --- a/toxcore/forwarding.h +++ b/toxcore/forwarding.h @@ -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); diff --git a/toxcore/group.c b/toxcore/group.c index 40e81a11b8..57a81ef28e 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -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); diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 2b917ff46e..901c73d529 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -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); diff --git a/toxcore/group_connection.c b/toxcore/group_connection.c index 880b7a2cfa..9d919361b9 100644 --- a/toxcore/group_connection.c +++ b/toxcore/group_connection.c @@ -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"); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 4d2aaac1b0..cf11ef1505 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -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); diff --git a/toxcore/onion.c b/toxcore/onion.c index 80bb49202f..3e5157520e 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -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; } diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index d4a37ad93b..ffe368e372 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -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; } diff --git a/toxcore/tox.c b/toxcore/tox.c index 62a4401667..290f6bb83a 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -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) {