From b13590a86d08542cdee603c1fbc3e998c7a012e3 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 23 Feb 2022 18:55:28 +0000 Subject: [PATCH] cleanup: Mark all local non-pointers as const where possible. --- .../docker/tox-bootstrapd.sha256 | 2 +- toxav/audio.c | 12 +-- toxav/bwcontroller.c | 2 +- toxav/groupav.c | 18 ++-- toxav/rtp.c | 4 +- toxav/toxav.c | 12 +-- toxav/video.c | 12 +-- toxcore/DHT.c | 4 +- toxcore/LAN_discovery.c | 8 +- toxcore/Messenger.c | 64 +++++------ toxcore/TCP_client.c | 18 ++-- toxcore/TCP_connection.c | 32 +++--- toxcore/TCP_server.c | 18 ++-- toxcore/crypto_core.c | 4 +- toxcore/group.c | 6 +- toxcore/list.c | 6 +- toxcore/mono_time.c | 2 +- toxcore/net_crypto.c | 100 +++++++++--------- toxcore/network.c | 24 ++--- toxcore/onion.c | 18 ++-- toxcore/onion_announce.c | 8 +- toxcore/onion_client.c | 42 ++++---- toxcore/tox.c | 18 ++-- toxcore/tox_api.c | 2 +- toxencryptsave/toxencryptsave.c | 6 +- 25 files changed, 221 insertions(+), 221 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index a4ea6979..1afa5e95 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -d69f99a7aa2e9290024b1dea3443fbfe9bfbaba444db5ccace5df2d88f15300a /usr/local/bin/tox-bootstrapd +dd4f76c70a0f0a4799b73ee372d81dbc6228e4b25890b7d5f4b0a89950e1c465 /usr/local/bin/tox-bootstrapd diff --git a/toxav/audio.c b/toxav/audio.c index 015c5e4f..5e98526f 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -140,7 +140,7 @@ void ac_iterate(ACSession *ac) if (rc == 2) { LOGGER_DEBUG(ac->log, "OPUS correction"); - int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000; + const int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000; rc = opus_decode(ac->decoder, nullptr, 0, temp_audio_buffer, fs, 1); } else { /* Get values from packet and decode. */ @@ -230,7 +230,7 @@ int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg) } pthread_mutex_lock(ac->queue_mutex); - int rc = jbuf_write(ac->log, (struct JitterBuffer *)ac->j_buf, msg); + const int rc = jbuf_write(ac->log, (struct JitterBuffer *)ac->j_buf, msg); pthread_mutex_unlock(ac->queue_mutex); if (rc == -1) { @@ -311,9 +311,9 @@ static void jbuf_free(struct JitterBuffer *q) } static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m) { - uint16_t sequnum = m->header.sequnum; + const uint16_t sequnum = m->header.sequnum; - unsigned int num = sequnum % q->size; + const unsigned int num = sequnum % q->size; if ((uint32_t)(sequnum - q->bottom) > q->size) { LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", (void *)q); @@ -344,7 +344,7 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success) return nullptr; } - unsigned int num = q->bottom % q->size; + const unsigned int num = q->bottom % q->size; if (q->queue[num] != nullptr) { struct RTPMessage *ret = q->queue[num]; @@ -474,7 +474,7 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32 return true; /* Nothing changed */ } - int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br)); + const int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br)); if (status != OPUS_OK) { LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status)); diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 49e24ba7..e7fb8f01 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -74,7 +74,7 @@ BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb, retu->m = m; retu->friend_number = friendnumber; retu->bwc_mono_time = bwc_mono_time; - uint64_t now = current_time_monotonic(bwc_mono_time); + const uint64_t now = current_time_monotonic(bwc_mono_time); retu->cycle.last_sent_timestamp = now; retu->cycle.last_refresh_timestamp = now; retu->tox = tox; diff --git a/toxav/groupav.c b/toxav/groupav.c index 584287a4..47c8ed94 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c @@ -90,9 +90,9 @@ static void terminate_queue(Group_JitterBuffer *q) */ static int queue(Group_JitterBuffer *q, const Mono_Time *mono_time, Group_Audio_Packet *pk) { - uint16_t sequnum = pk->sequnum; + const uint16_t sequnum = pk->sequnum; - unsigned int num = sequnum % q->size; + const unsigned int num = sequnum % q->size; if (!mono_time_is_timeout(mono_time, q->last_queued_time, GROUP_JBUF_DEAD_SECONDS)) { if ((uint32_t)(sequnum - q->bottom) > (1 << 15)) { @@ -132,7 +132,7 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success) return nullptr; } - unsigned int num = q->bottom % q->size; + const unsigned int num = q->bottom % q->size; if (q->queue[num] != nullptr) { Group_Audio_Packet *ret = q->queue[num]; @@ -304,10 +304,10 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3 int16_t *out_audio = nullptr; int out_audio_samples = 0; - unsigned int sample_rate = 48000; + const unsigned int sample_rate = 48000; if (success == 1) { - int channels = opus_packet_get_nb_channels(pk->data); + const int channels = opus_packet_get_nb_channels(pk->data); if (channels == OPUS_INVALID_PACKET) { free_audio_packet(pk); @@ -337,7 +337,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3 peer_av->decoder_channels = channels; } - int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length); + const int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length); out_audio = (int16_t *)malloc(num_samples * peer_av->decoder_channels * sizeof(int16_t)); @@ -529,7 +529,7 @@ bool groupchat_av_enabled(const Group_Chats *g_c, uint32_t groupnumber) */ int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata) { - int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); + const int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); if (groupnumber == -1) { return -1; @@ -551,7 +551,7 @@ int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_c int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, audio_data_cb *audio_callback, void *userdata) { - int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length); + const int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length); if (groupnumber == -1) { return -1; @@ -640,7 +640,7 @@ int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, } uint8_t encoded[1024]; - int32_t size = opus_encode(group_av->audio_encoder, pcm, samples, encoded, sizeof(encoded)); + const int32_t size = opus_encode(group_av->audio_encoder, pcm, samples, encoded, sizeof(encoded)); if (size <= 0) { return -1; diff --git a/toxav/rtp.c b/toxav/rtp.c index 0c4c4ac8..e9c4f42c 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -314,8 +314,8 @@ static void update_bwc_values(const Logger *log, RTPSession *session, const stru if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) { ++session->first_packets_counter; } else { - uint32_t data_length_full = msg->header.data_length_full; // without header - uint32_t received_length_full = msg->header.received_length_full; // without header + const uint32_t data_length_full = msg->header.data_length_full; // without header + const uint32_t received_length_full = msg->header.received_length_full; // without header bwc_add_recv(session->bwc, data_length_full); if (received_length_full < data_length_full) { diff --git a/toxav/toxav.c b/toxav/toxav.c index 118f9584..ea389178 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -300,7 +300,7 @@ static void iterate_common(ToxAV *av, bool audio) return; } - uint64_t start = current_time_monotonic(av->toxav_mono_time); + const uint64_t start = current_time_monotonic(av->toxav_mono_time); // time until the first audio or video frame is over int32_t frame_time = IDLE_ITERATION_INTERVAL_MS; @@ -330,7 +330,7 @@ static void iterate_common(ToxAV *av, bool audio) } } - uint32_t fid = i->friend_number; + const uint32_t fid = i->friend_number; pthread_mutex_unlock(i->toxav_call_mutex); pthread_mutex_lock(av->mutex); @@ -628,7 +628,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co { pthread_mutex_lock(av->mutex); - Toxav_Err_Call_Control rc = call_control(av, friend_number, control); + const Toxav_Err_Call_Control rc = call_control(av, friend_number, control); pthread_mutex_unlock(av->mutex); @@ -854,7 +854,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc sampling_rate = net_htonl(sampling_rate); memcpy(dest, &sampling_rate, sizeof(sampling_rate)); - int vrc = opus_encode(call->audio->encoder, pcm, sample_count, + const int vrc = opus_encode(call->audio->encoder, pcm, sample_count, dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate)); if (vrc < 0) { @@ -1001,7 +1001,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2)); memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); - vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img, + const vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img, call->video->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US); vpx_img_free(&img); @@ -1338,7 +1338,7 @@ static ToxAVCall *call_remove(ToxAVCall *call) return nullptr; } - uint32_t friend_number = call->friend_number; + const uint32_t friend_number = call->friend_number; ToxAV *av = call->av; ToxAVCall *prev = call->prev; diff --git a/toxav/video.c b/toxav/video.c index a6a3f47f..a2a3510f 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -73,7 +73,7 @@ static vpx_codec_iface_t *video_codec_encoder_interface(void) static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) { - vpx_codec_err_t rc = vpx_codec_enc_config_default(video_codec_encoder_interface(), cfg, 0); + const vpx_codec_err_t rc = vpx_codec_enc_config_default(video_codec_encoder_interface(), cfg, 0); if (rc != VPX_CODEC_OK) { LOGGER_ERROR(log, "vc_init_encoder_cfg:Failed to get config: %s", vpx_codec_err_to_string(rc)); @@ -157,7 +157,7 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f return nullptr; } - int cpu_used_value = VP8E_SET_CPUUSED_VALUE; + const int cpu_used_value = VP8E_SET_CPUUSED_VALUE; vc->vbuf_raw = rb_new(VIDEO_DECODE_BUFFER_SIZE); @@ -193,7 +193,7 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f if (VIDEO_VP8_DECODER_POST_PROCESSING_ENABLED == 1) { vp8_postproc_cfg_t pp = {VP8_DEBLOCK, 1, 0}; - vpx_codec_err_t cc_res = vpx_codec_control(vc->decoder, VP8_SET_POSTPROC, &pp); + const vpx_codec_err_t cc_res = vpx_codec_control(vc->decoder, VP8_SET_POSTPROC, &pp); if (cc_res != VPX_CODEC_OK) { LOGGER_WARNING(log, "Failed to turn on postproc"); @@ -300,7 +300,7 @@ void vc_iterate(VCSession *vc) return; } - uint16_t log_rb_size = rb_size(vc->vbuf_raw); + const uint16_t log_rb_size = rb_size(vc->vbuf_raw); pthread_mutex_unlock(vc->queue_mutex); const struct RTPHeader *const header = &p->header; @@ -376,7 +376,7 @@ int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg) free(rb_write(vc->vbuf_raw, msg)); /* Calculate time it took for peer to send us this frame */ - uint32_t t_lcfd = current_time_monotonic(mono_time) - vc->linfts; + const uint32_t t_lcfd = current_time_monotonic(mono_time) - vc->linfts; vc->lcfd = t_lcfd > 100 ? vc->lcfd : t_lcfd; vc->linfts = current_time_monotonic(mono_time); pthread_mutex_unlock(vc->queue_mutex); @@ -426,7 +426,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin return -1; } - int cpu_used_value = VP8E_SET_CPUUSED_VALUE; + const int cpu_used_value = VP8E_SET_CPUUSED_VALUE; rc = vpx_codec_control(&new_c, VP8E_SET_CPUUSED, cpu_used_value); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 8a40e3ee..699e8582 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1810,7 +1810,7 @@ static void do_Close(DHT *dht) dht->num_to_bootstrap = 0; - uint8_t not_killed = do_ping_and_sendnode_requests( + const uint8_t not_killed = do_ping_and_sendnode_requests( dht, &dht->close_lastgetnodes, dht->self_public_key, dht->close_clientlist, LCLIENT_LIST, &dht->close_bootstrap_times, 0); @@ -2171,7 +2171,7 @@ static int handle_NATping(void *object, const IP_Port *source, const uint8_t *so uint64_t ping_id; memcpy(&ping_id, packet + 1, sizeof(uint64_t)); - uint32_t friendnumber = index_of_friend_pk(dht->friends_list, dht->num_friends, source_pubkey); + const uint32_t friendnumber = index_of_friend_pk(dht->friends_list, dht->num_friends, source_pubkey); if (friendnumber == UINT32_MAX) { return 1; diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 55c36f87..82f0dd5f 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -91,9 +91,9 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port) if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) { IP_Port *ip_port = &broadcast->ip_ports[broadcast->count]; ip_port->ip.family = net_family_ipv4; - uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32); - uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32); - uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; + const uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32); + const uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32); + const uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; ip_port->ip.ip.v4.uint32 = net_htonl(broadcast_ip); ip_port->port = port; ++broadcast->count; @@ -155,7 +155,7 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port) * a larger array, not done (640kB and 16 interfaces shall be * enough, for everybody!) */ - int n = ifc.ifc_len / sizeof(struct ifreq); + const int n = ifc.ifc_len / sizeof(struct ifreq); for (int i = 0; i < n; ++i) { /* there are interfaces with are incapable of broadcast */ diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fb84e21a..8ff3c81a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -175,7 +175,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta memset(&m->friendlist[m->numfriends], 0, sizeof(Friend)); - int friendcon_id = new_friend_connection(m->fr_c, real_pk); + const int friendcon_id = new_friend_connection(m->fr_c, real_pk); if (friendcon_id == -1) { return FAERR_NOMEM; @@ -244,7 +244,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u } uint16_t check; - uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); + const uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); memcpy(&check, address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t), sizeof(check)); if (check != checksum) { @@ -259,7 +259,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u return FAERR_OWNKEY; } - int32_t friend_id = getfriend_id(m, real_pk); + const int32_t friend_id = getfriend_id(m, real_pk); if (friend_id != -1) { if (m->friendlist[friend_id].status >= FRIEND_CONFIRMED) { @@ -277,7 +277,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u return FAERR_SETNEWNOSPAM; } - int32_t ret = init_new_friend(m, real_pk, FRIEND_ADDED); + const int32_t ret = init_new_friend(m, real_pk, FRIEND_ADDED); if (ret < 0) { return ret; @@ -459,7 +459,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) bool direct_connected = 0; uint32_t num_online_relays = 0; - int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id); + const int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id); if (!crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays)) { return CONNECTION_NONE; @@ -530,7 +530,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con memcpy(packet + 1, message, length); } - int64_t packet_num = write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, + const int64_t packet_num = write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id), packet, length + 1, 0); if (packet_num == -1) { @@ -539,7 +539,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con return -4; } - uint32_t msg_id = ++m->friendlist[friendnumber].message_id; + const uint32_t msg_id = ++m->friendlist[friendnumber].message_id; add_receipt(m, friendnumber, packet_num, msg_id); @@ -761,7 +761,7 @@ int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, // TODO(iphydf): This should be uint16_t and min_u16. If maxlen exceeds // uint16_t's range, it won't affect the result. - uint32_t msglen = min_u32(maxlen, m->friendlist[friendnumber].statusmessage_length); + const uint32_t msglen = min_u32(maxlen, m->friendlist[friendnumber].statusmessage_length); memcpy(buf, m->friendlist[friendnumber].statusmessage, msglen); memset(buf + msglen, 0, maxlen - msglen); @@ -947,9 +947,9 @@ void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionst non_null(1) nullable(3) static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata) { - int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp; + const int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp; - int ret = m_get_friend_connectionstatus(m, friendnumber); + const int ret = m_get_friend_connectionstatus(m, friendnumber); if (ret == -1) { return; @@ -1347,14 +1347,14 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin return -4; } - uint32_t temp_filenum = (filenumber >> 16) - 1; + const uint32_t temp_filenum = (filenumber >> 16) - 1; if (temp_filenum >= MAX_CONCURRENT_FILE_PIPES) { return -3; } assert(temp_filenum <= UINT8_MAX); - uint8_t file_number = temp_filenum; + const uint8_t file_number = temp_filenum; // We're always receiving at this point. struct File_Transfers *ft = &m->friendlist[friendnumber].file_receiving[file_number]; @@ -1468,7 +1468,7 @@ int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber return -6; } - int64_t ret = send_file_data_packet(m, friendnumber, filenumber, data, length); + const int64_t ret = send_file_data_packet(m, friendnumber, filenumber, data, length); if (ret != -1) { // TODO(irungentoo): record packet ids to check if other received complete file. @@ -1974,9 +1974,9 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le } Messenger *m = (Messenger *)object; - uint8_t packet_id = temp[0]; + const uint8_t packet_id = temp[0]; const uint8_t *data = temp + 1; - uint16_t data_length = len - 1; + const uint16_t data_length = len - 1; if (m->friendlist[i].status != FRIEND_ONLINE) { if (packet_id == PACKET_ID_ONLINE && len == 1) { @@ -2041,7 +2041,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le break; } - Userstatus status = (Userstatus)data[0]; + const Userstatus status = (Userstatus)data[0]; if (status >= USERSTATUS_INVALID) { break; @@ -2060,7 +2060,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le break; } - bool typing = !!data[0]; + const bool typing = !!data[0]; set_friend_typing(m, i, typing); @@ -2078,13 +2078,13 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le } const uint8_t *message = data; - uint16_t message_length = data_length; + const uint16_t message_length = data_length; /* Make sure the NULL terminator is present. */ VLA(uint8_t, message_terminated, message_length + 1); memcpy(message_terminated, message, message_length); message_terminated[message_length] = 0; - uint8_t type = packet_id - PACKET_ID_MESSAGE; + const uint8_t type = packet_id - PACKET_ID_MESSAGE; if (m->friend_message != nullptr) { m->friend_message(m, i, type, message_terminated, message_length, userdata); @@ -2112,7 +2112,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le break; } - uint8_t filenumber = data[0]; + const uint8_t filenumber = data[0]; #if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES @@ -2124,7 +2124,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le uint64_t filesize; uint32_t file_type; - uint16_t filename_length = data_length - head_length; + const uint16_t filename_length = data_length - head_length; if (filename_length > MAX_FILENAME_LENGTH) { break; @@ -2173,9 +2173,9 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le break; } - uint8_t send_receive = data[0]; + const uint8_t send_receive = data[0]; uint8_t filenumber = data[1]; - uint8_t control_type = data[2]; + const uint8_t control_type = data[2]; #if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES @@ -2282,11 +2282,11 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le non_null(1) nullable(2) static void do_friends(Messenger *m, void *userdata) { - uint64_t temp_time = mono_time_get(m->mono_time); + const uint64_t temp_time = mono_time_get(m->mono_time); for (uint32_t i = 0; i < m->numfriends; ++i) { if (m->friendlist[i].status == FRIEND_ADDED) { - int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam, + const int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info, m->friendlist[i].info_size); @@ -2343,7 +2343,7 @@ static void do_friends(Messenger *m, void *userdata) non_null(1) nullable(2) static void connection_status_callback(Messenger *m, void *userdata) { - Onion_Connection_Status conn_status = onion_connection_status(m->onion_c); + const Onion_Connection_Status conn_status = onion_connection_status(m->onion_c); if (conn_status != m->last_connection_status) { if (m->core_connection_change != nullptr) { @@ -2386,7 +2386,7 @@ static char *id_to_string(const uint8_t *pk, char *id_str, size_t length) */ uint32_t messenger_run_interval(const Messenger *m) { - uint32_t crypto_interval = crypto_run_interval(m->net_crypto); + const uint32_t crypto_interval = crypto_run_interval(m->net_crypto); if (crypto_interval > MIN_RUN_INTERVAL) { return MIN_RUN_INTERVAL; @@ -2463,7 +2463,7 @@ void do_messenger(Messenger *m, void *userdata) /* dht contains additional "friends" (requests) */ - uint32_t num_dhtfriends = dht_get_num_friends(m->dht); + const uint32_t num_dhtfriends = dht_get_num_friends(m->dht); VLA(int32_t, m2dht, num_dhtfriends); VLA(int32_t, dht2m, num_dhtfriends); @@ -2778,7 +2778,7 @@ static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data) const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS); assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t)); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_NOSPAMKEYS); - uint32_t nospam = get_nospam(m->fr); + const uint32_t nospam = get_nospam(m->fr); host_to_lendian_bytes32(data, nospam); save_keys(m->net_crypto, data + sizeof(uint32_t)); data += len; @@ -2876,7 +2876,7 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui return STATE_LOAD_STATUS_ERROR; // TODO(endoffile78): error or continue? } - uint32_t num = length / l_friend_size; + const uint32_t num = length / l_friend_size; const uint8_t *cur_data = data; for (uint32_t i = 0; i < num; ++i) { @@ -2887,7 +2887,7 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui cur_data = next_data; if (temp.status >= 3) { - int fnum = m_addfriend_norequest(m, temp.real_pk); + const int fnum = m_addfriend_norequest(m, temp.real_pk); if (fnum < 0) { continue; @@ -3013,7 +3013,7 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data) uint32_t num = m->num_loaded_relays; num += copy_connected_tcp_relays(m->net_crypto, relays + num, NUM_SAVED_TCP_RELAYS - num); - int l = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6), relays, num); + const int l = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6), relays, num); if (l > 0) { const uint32_t len = l; diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 5cebb957..0b2b6bcc 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -150,7 +150,7 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C char success[] = "200"; uint8_t data[16]; // draining works the best if the length is a power of 2 - int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data) - 1, &tcp_conn->con.ip_port); + const int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data) - 1, &tcp_conn->con.ip_port); if (ret == -1) { return 0; @@ -201,7 +201,7 @@ non_null() static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn) { uint8_t data[2]; - int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data), &tcp_conn->con.ip_port); + const int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data), &tcp_conn->con.ip_port); if (ret == -1) { return 0; @@ -250,7 +250,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP { if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) { uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; - int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data), &tcp_conn->con.ip_port); + const int ret = read_TCP_packet(logger, tcp_conn->con.sock, data, sizeof(data), &tcp_conn->con.ip_port); if (ret == -1) { return 0; @@ -287,7 +287,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn) memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, tcp_conn->con.sent_nonce, CRYPTO_NONCE_SIZE); memcpy(tcp_conn->con.last_packet, tcp_conn->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); random_nonce(tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE); - int len = encrypt_data_symmetric(tcp_conn->con.shared_key, tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE, plain, + const int len = encrypt_data_symmetric(tcp_conn->con.shared_key, tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE, plain, sizeof(plain), tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); if (len != sizeof(plain) + CRYPTO_MAC_SIZE) { @@ -308,7 +308,7 @@ non_null() static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data) { uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE]; - int len = decrypt_data_symmetric(tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE, + const int len = decrypt_data_symmetric(tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE, TCP_SERVER_HANDSHAKE_SIZE - CRYPTO_NONCE_SIZE, plain); if (len != sizeof(plain)) { @@ -540,7 +540,7 @@ TCP_Client_Connection *new_TCP_connection(const Logger *logger, const Mono_Time family = proxy_info->ip_port.ip.family; } - Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP); + const Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP); if (!sock_valid(sock)) { return nullptr; @@ -623,7 +623,7 @@ static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection return 0; } - uint8_t con_id = data[1] - NUM_RESERVED_PORTS; + const uint8_t con_id = data[1] - NUM_RESERVED_PORTS; if (conn->connections[con_id].status != 0) { return 0; @@ -829,7 +829,7 @@ void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time, if (tcp_connection->status == TCP_CLIENT_PROXY_HTTP_CONNECTING) { if (send_pending_data(logger, &tcp_connection->con) == 0) { - int ret = proxy_http_read_connection_response(logger, tcp_connection); + const int ret = proxy_http_read_connection_response(logger, tcp_connection); if (ret == -1) { tcp_connection->kill_at = 0; @@ -883,7 +883,7 @@ void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time, if (tcp_connection->status == TCP_CLIENT_UNCONFIRMED) { uint8_t data[TCP_SERVER_HANDSHAKE_SIZE]; - int len = read_TCP_packet(logger, tcp_connection->con.sock, data, sizeof(data), &tcp_connection->con.ip_port); + const int len = read_TCP_packet(logger, tcp_connection->con.sock, data, sizeof(data), &tcp_connection->con.ip_port); if (sizeof(data) == len) { if (handle_handshake(tcp_connection, data) == 0) { diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index a39c19e5..0edec143 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -309,8 +309,8 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { uint32_t tcp_con_num = con_to->connections[i].tcp_connection; - uint8_t status = con_to->connections[i].status; - uint8_t connection_id = con_to->connections[i].connection_id; + const uint8_t status = con_to->connections[i].status; + const uint8_t connection_id = con_to->connections[i].connection_id; if (tcp_con_num > 0 && status == TCP_CONNECTIONS_STATUS_ONLINE) { tcp_con_num -= 1; @@ -381,7 +381,7 @@ int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c) const uint32_t r = random_u32(); for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { - uint32_t index = (i + r) % tcp_c->tcp_connections_length; + const uint32_t index = (i + r) % tcp_c->tcp_connections_length; if (tcp_c->tcp_connections[index].onion && tcp_c->tcp_connections[index].status == TCP_CONN_CONNECTED) { return index; @@ -453,7 +453,7 @@ static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key, const uint8_t *packet, uint16_t length) { - int tcp_con_number = find_tcp_connection_relay(tcp_c, relay_pk); + const int tcp_con_number = find_tcp_connection_relay(tcp_c, relay_pk); if (tcp_con_number < 0) { return -1; @@ -548,7 +548,7 @@ int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int return -1; } - int connections_number = create_connection(tcp_c); + const int connections_number = create_connection(tcp_c); if (connections_number == -1) { return -1; @@ -576,7 +576,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number) for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { if (con_to->connections[i].tcp_connection > 0) { - unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; + const unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); if (tcp_con == nullptr) { @@ -626,7 +626,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { if (con_to->connections[i].tcp_connection > 0) { - unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; + const unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); if (tcp_con == nullptr) { @@ -946,14 +946,14 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object; const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con); - unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); + const unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); if (tcp_con == nullptr) { return -1; } - int connections_number = find_tcp_connection_to(tcp_c, public_key); + const int connections_number = find_tcp_connection_to(tcp_c, public_key); if (connections_number == -1) { return -1; @@ -980,7 +980,7 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection 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); - unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); + const unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_Connection_to *con_to = get_connection(tcp_c, number); @@ -1024,7 +1024,7 @@ static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connect const TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object; TCP_Connections *tcp_c = (TCP_Connections *)tcp_con_custom_object(tcp_client_con); - unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); + const unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); const TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); if (tcp_con == nullptr) { @@ -1055,7 +1055,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object; TCP_Connections *tcp_c = (TCP_Connections *)tcp_con_custom_object(tcp_client_con); - unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); + const unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con); const TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); if (tcp_con == nullptr) { @@ -1063,7 +1063,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const } /* TODO(irungentoo): optimize */ - int connections_number = find_tcp_connection_to(tcp_c, public_key); + const int connections_number = find_tcp_connection_to(tcp_c, public_key); const TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); @@ -1173,7 +1173,7 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port return -1; } - int tcp_connections_number = create_tcp_connection(tcp_c); + const int tcp_connections_number = create_tcp_connection(tcp_c); if (tcp_connections_number == -1) { return -1; @@ -1200,7 +1200,7 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port */ int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk) { - int tcp_connections_number = find_tcp_connection_relay(tcp_c, relay_pk); + const int tcp_connections_number = find_tcp_connection_relay(tcp_c, relay_pk); if (tcp_connections_number != -1) { return -1; @@ -1412,7 +1412,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status) } if (tcp_c->onion_num_conns < NUM_ONION_TCP_CONNECTIONS) { - unsigned int wakeup = NUM_ONION_TCP_CONNECTIONS - tcp_c->onion_num_conns; + const unsigned int wakeup = NUM_ONION_TCP_CONNECTIONS - tcp_c->onion_num_conns; for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { TCP_con *tcp_con = get_tcp_connection(tcp_c, i); diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index ab5fd91e..225ffaa6 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -283,7 +283,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index) rm_connection_index(tcp_server, &tcp_server->accepted_connection_array[index], i); } - Socket sock = tcp_server->accepted_connection_array[index].con.sock; + const Socket sock = tcp_server->accepted_connection_array[index].con.sock; if (del_accepted(tcp_server, index) != 0) { return -1; @@ -452,7 +452,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const return 0; } - int ret = send_routing_response(tcp_server->logger, con, index + NUM_RESERVED_PORTS, public_key); + const int ret = send_routing_response(tcp_server->logger, con, index + NUM_RESERVED_PORTS, public_key); if (ret == 0) { return 0; @@ -464,7 +464,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const con->connections[index].status = 1; memcpy(con->connections[index].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); - int other_index = get_TCP_connection_index(tcp_server, public_key); + const int other_index = get_TCP_connection_index(tcp_server, public_key); if (other_index != -1) { uint32_t other_id = -1; @@ -507,7 +507,7 @@ static int handle_TCP_oob_send(TCP_Server *tcp_server, uint32_t con_id, const ui const TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id]; - int other_index = get_TCP_connection_index(tcp_server, public_key); + const int other_index = get_TCP_connection_index(tcp_server, public_key); if (other_index != -1) { VLA(uint8_t, resp_packet, 1 + CRYPTO_PUBLIC_KEY_SIZE + length); @@ -561,7 +561,7 @@ non_null() static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length) { TCP_Server *tcp_server = (TCP_Server *)object; - uint32_t index = dest->ip.ip.v6.uint32[0]; + const uint32_t index = dest->ip.ip.v6.uint32[0]; if (index >= tcp_server->size_accepted_connections) { return 1; @@ -800,7 +800,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock) non_null() static Socket new_listening_TCP_socket(const Logger *logger, Family family, uint16_t port) { - Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP); + const Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP); if (!sock_valid(sock)) { LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family.value); @@ -876,7 +876,7 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t const Family family = ipv6_enabled ? net_family_ipv6 : net_family_ipv4; for (uint32_t i = 0; i < num_sockets; ++i) { - Socket sock = new_listening_TCP_socket(logger, family, ports[i]); + const Socket sock = new_listening_TCP_socket(logger, family, ports[i]); if (!sock_valid(sock)) { continue; @@ -1080,7 +1080,7 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time) } memcpy(ping + 1, &ping_id, sizeof(uint64_t)); - int ret = write_packet_TCP_secure_connection(tcp_server->logger, &conn->con, ping, sizeof(ping), 1); + const int ret = write_packet_TCP_secure_connection(tcp_server->logger, &conn->con, ping, sizeof(ping), 1); if (ret == 1) { conn->last_pinged = mono_time_get(mono_time); @@ -1161,7 +1161,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time case TCP_SOCKET_LISTENING: { // socket is from socks_listening, accept connection while (1) { - Socket sock_new = net_accept(sock); + const Socket sock_new = net_accept(sock); if (!sock_valid(sock_new)) { break; diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 7bcf383e..f5ccee8e 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -302,7 +302,7 @@ int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t k[crypto_box_BEFORENMBYTES]; encrypt_precompute(public_key, secret_key, k); - int ret = encrypt_data_symmetric(k, nonce, plain, length, encrypted); + const int ret = encrypt_data_symmetric(k, nonce, plain, length, encrypted); crypto_memzero(k, sizeof(k)); return ret; } @@ -316,7 +316,7 @@ int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t k[crypto_box_BEFORENMBYTES]; encrypt_precompute(public_key, secret_key, k); - int ret = decrypt_data_symmetric(k, nonce, encrypted, length, plain); + const int ret = decrypt_data_symmetric(k, nonce, encrypted, length, plain); crypto_memzero(k, sizeof(k)); return ret; } diff --git a/toxcore/group.c b/toxcore/group.c index a1c6e79b..0a7cf51a 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -122,7 +122,7 @@ static int32_t create_group_chat(Group_Chats *g_c) } if (realloc_conferences(g_c, g_c->num_chats + 1)) { - uint16_t id = g_c->num_chats; + const uint16_t id = g_c->num_chats; ++g_c->num_chats; setup_conference(&g_c->chats[id]); return id; @@ -309,7 +309,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te uint64_t comp_d = 0; for (unsigned int i = 0; i < (DESIRED_CLOSEST / 2); ++i) { - uint64_t comp = calculate_comp_value(g->real_pk, g->closest_peers[i].real_pk); + const uint64_t comp = calculate_comp_value(g->real_pk, g->closest_peers[i].real_pk); if (comp > comp_val && comp > comp_d) { index = i; @@ -2533,7 +2533,7 @@ static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint memcpy(packet + sizeof(uint16_t) + sizeof(uint32_t) + 1, data, len); } - unsigned int ret = send_message_all_connections(g_c, g, packet, SIZEOF_VLA(packet), -1); + const unsigned int ret = send_message_all_connections(g_c, g, packet, SIZEOF_VLA(packet), -1); if (ret == 0) { return -4; diff --git a/toxcore/list.c b/toxcore/list.c index 4f80f35a..4bbdcbd3 100644 --- a/toxcore/list.c +++ b/toxcore/list.c @@ -59,7 +59,7 @@ static int find(const BS_List *list, const uint8_t *data) // closest match is found if we move back to where we have already been while (1) { - int r = memcmp(data, list->data + list->element_size * i, list->element_size); + const int r = memcmp(data, list->data + list->element_size * i, list->element_size); if (r == 0) { return i; @@ -166,7 +166,7 @@ void bs_list_free(BS_List *list) int bs_list_find(const BS_List *list, const uint8_t *data) { - int r = find(list, data); + const int r = find(list, data); // return only -1 and positive values if (r < 0) { @@ -218,7 +218,7 @@ int bs_list_add(BS_List *list, const uint8_t *data, int id) int bs_list_remove(BS_List *list, const uint8_t *data, int id) { - int i = find(list, data); + const int i = find(list, data); if (i < 0) { return 0; diff --git a/toxcore/mono_time.c b/toxcore/mono_time.c index 7673b2d4..c75c53ac 100644 --- a/toxcore/mono_time.c +++ b/toxcore/mono_time.c @@ -66,7 +66,7 @@ static uint64_t current_time_monotonic_default(Mono_Time *mono_time, void *user_ * GetTickCount64 for backwards compatibility, so we handle wraparound * ourselves. */ - uint32_t ticks = GetTickCount(); + const uint32_t ticks = GetTickCount(); /* the higher 32 bits count the number of wrap arounds */ uint64_t old_ovf = mono_time->cur_time & ~((uint64_t)UINT32_MAX); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 6de40f43..b953b13e 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -226,7 +226,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uin packet[0] = NET_PACKET_COOKIE_REQUEST; memcpy(packet + 1, dht_get_self_public_key(c->dht), CRYPTO_PUBLIC_KEY_SIZE); memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); - int len = encrypt_data_symmetric(shared_key, nonce, plain, sizeof(plain), + const int len = encrypt_data_symmetric(shared_key, nonce, plain, sizeof(plain), packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); if (len != COOKIE_REQUEST_PLAIN_LENGTH + CRYPTO_MAC_SIZE) { @@ -250,7 +250,7 @@ static int create_cookie(const Mono_Time *mono_time, uint8_t *cookie, const uint memcpy(contents, &temp_time, sizeof(temp_time)); memcpy(contents + sizeof(temp_time), bytes, COOKIE_DATA_LENGTH); random_nonce(cookie); - int len = encrypt_data_symmetric(encryption_key, cookie, contents, sizeof(contents), cookie + CRYPTO_NONCE_SIZE); + const int len = encrypt_data_symmetric(encryption_key, cookie, contents, sizeof(contents), cookie + CRYPTO_NONCE_SIZE); if (len != COOKIE_LENGTH - CRYPTO_NONCE_SIZE) { return -1; @@ -312,7 +312,7 @@ static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const ui memcpy(plain + COOKIE_LENGTH, request_plain + COOKIE_DATA_LENGTH, sizeof(uint64_t)); packet[0] = NET_PACKET_COOKIE_RESPONSE; random_nonce(packet + 1); - int len = encrypt_data_symmetric(shared_key, packet + 1, plain, sizeof(plain), packet + 1 + CRYPTO_NONCE_SIZE); + const int len = encrypt_data_symmetric(shared_key, packet + 1, plain, sizeof(plain), packet + 1 + CRYPTO_NONCE_SIZE); if (len != COOKIE_RESPONSE_LENGTH - (1 + CRYPTO_NONCE_SIZE)) { return -1; @@ -338,7 +338,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui memcpy(dht_public_key, packet + 1, CRYPTO_PUBLIC_KEY_SIZE); dht_get_shared_key_sent(c->dht, shared_key, dht_public_key); - int len = decrypt_data_symmetric(shared_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, + const int len = decrypt_data_symmetric(shared_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, COOKIE_REQUEST_PLAIN_LENGTH + CRYPTO_MAC_SIZE, request_plain); @@ -397,7 +397,7 @@ static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number return -1; } - int ret = send_packet_tcp_connection(c->tcp_c, connections_number, data, sizeof(data)); + const int ret = send_packet_tcp_connection(c->tcp_c, connections_number, data, sizeof(data)); return ret; } @@ -425,7 +425,7 @@ static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_c return -1; } - int ret = tcp_send_oob_packet(c->tcp_c, tcp_connections_number, dht_public_key, data, sizeof(data)); + const int ret = tcp_send_oob_packet(c->tcp_c, tcp_connections_number, dht_public_key, data, sizeof(data)); return ret; } @@ -486,7 +486,7 @@ static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const u } random_nonce(packet + 1 + COOKIE_LENGTH); - int len = encrypt_data(peer_real_pk, c->self_secret_key, packet + 1 + COOKIE_LENGTH, plain, sizeof(plain), + const int len = encrypt_data(peer_real_pk, c->self_secret_key, packet + 1 + COOKIE_LENGTH, plain, sizeof(plain), packet + 1 + COOKIE_LENGTH + CRYPTO_NONCE_SIZE); if (len != HANDSHAKE_PACKET_LENGTH - (1 + COOKIE_LENGTH + CRYPTO_NONCE_SIZE)) { @@ -539,7 +539,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t crypto_sha512(cookie_hash, packet + 1, COOKIE_LENGTH); uint8_t plain[CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE + COOKIE_LENGTH]; - int len = decrypt_data(cookie_plain, c->self_secret_key, packet + 1 + COOKIE_LENGTH, + const int len = decrypt_data(cookie_plain, c->self_secret_key, packet + 1 + COOKIE_LENGTH, packet + 1 + COOKIE_LENGTH + CRYPTO_NONCE_SIZE, HANDSHAKE_PACKET_LENGTH - (1 + COOKIE_LENGTH + CRYPTO_NONCE_SIZE), plain); @@ -762,7 +762,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe return -1; } - uint32_t num = number % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = number % CRYPTO_PACKET_BUFFER_SIZE; if (array->buffer[num] != nullptr) { return -1; @@ -799,7 +799,7 @@ static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint return -1; } - uint32_t num = number % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = number % CRYPTO_PACKET_BUFFER_SIZE; if (array->buffer[num] == nullptr) { return 0; @@ -832,7 +832,7 @@ static int64_t add_data_end_of_buffer(const Logger *logger, Packets_Array *array } *new_d = *data; - uint32_t id = array->buffer_end; + const uint32_t id = array->buffer_end; array->buffer[id % CRYPTO_PACKET_BUFFER_SIZE] = new_d; ++array->buffer_end; return id; @@ -857,7 +857,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data) } *data = *array->buffer[num]; - uint32_t id = array->buffer_start; + const uint32_t id = array->buffer_start; ++array->buffer_start; free(array->buffer[num]); array->buffer[num] = nullptr; @@ -881,7 +881,7 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number) uint32_t i; for (i = array->buffer_start; i != number; ++i) { - uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; if (array->buffer[num] != nullptr) { free(array->buffer[num]); @@ -899,7 +899,7 @@ static int clear_buffer(Packets_Array *array) uint32_t i; for (i = array->buffer_start; i != array->buffer_end; ++i) { - uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; if (array->buffer[num] != nullptr) { free(array->buffer[num]); @@ -959,7 +959,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets uint32_t n = 1; for (uint32_t i = recv_array->buffer_start; i != recv_array->buffer_end; ++i) { - uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; if (recv_array->buffer[num] == nullptr) { data[cur_len] = n; @@ -1022,11 +1022,11 @@ static int handle_request_packet(Mono_Time *mono_time, Packets_Array *send_array break; } - uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; + const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; if (n == data[0]) { if (send_array->buffer[num] != nullptr) { - uint64_t sent_time = send_array->buffer[num]->sent_time; + const uint64_t sent_time = send_array->buffer[num]->sent_time; if ((sent_time + rtt_time) < temp_time) { send_array->buffer[num]->sent_time = 0; @@ -1126,7 +1126,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3 num = net_htonl(num); buffer_start = net_htonl(buffer_start); - uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING; + const uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING; VLA(uint8_t, packet, sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length); memcpy(packet, &buffer_start, sizeof(uint32_t)); memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t)); @@ -1263,12 +1263,12 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint uint8_t nonce[CRYPTO_NONCE_SIZE]; memcpy(nonce, conn->recv_nonce, CRYPTO_NONCE_SIZE); - uint16_t num_cur_nonce = get_nonce_uint16(nonce); + const uint16_t num_cur_nonce = get_nonce_uint16(nonce); uint16_t num; net_unpack_u16(packet + 1, &num); - uint16_t diff = num - num_cur_nonce; + const uint16_t diff = num - num_cur_nonce; increment_nonce_number(nonce, diff); - int len = decrypt_data_symmetric(conn->shared_key, nonce, packet + 1 + sizeof(uint16_t), + const int len = decrypt_data_symmetric(conn->shared_key, nonce, packet + 1 + sizeof(uint16_t), length - (1 + sizeof(uint16_t)), data); if ((unsigned int)len != length - crypto_packet_overhead) { @@ -1297,7 +1297,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id) } uint8_t data[MAX_CRYPTO_DATA_SIZE]; - int len = generate_request_packet(data, sizeof(data), &conn->recv_array); + const int len = generate_request_packet(data, sizeof(data), &conn->recv_array); if (len == -1) { return -1; @@ -1548,7 +1548,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const } uint8_t data[MAX_DATA_DATA_PACKET_SIZE]; - int len = handle_data_packet(c, crypt_connection_id, data, packet, length); + const int len = handle_data_packet(c, crypt_connection_id, data, packet, length); if (len <= (int)(sizeof(uint32_t) * 2)) { return -1; @@ -1611,7 +1611,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const rtt_time = DEFAULT_TCP_PING_CONNECTION; } - int requested = handle_request_packet(c->mono_time, &conn->send_array, + const int requested = handle_request_packet(c->mono_time, &conn->send_array, real_data, real_length, &rtt_calc_time, rtt_time); @@ -2061,7 +2061,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, const IP_Port *source, } } - int ret = c->new_connection_callback(c->new_connection_callback_object, &n_c); + const int ret = c->new_connection_callback(c->new_connection_callback_object, &n_c); free(n_c.cookie); return ret; } @@ -2238,7 +2238,7 @@ static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_ // This unlocks the mutex that at this point is locked by do_tcp before // calling do_tcp_connections. pthread_mutex_unlock(&c->tcp_mutex); - int ret = handle_packet_connection(c, crypt_connection_id, data, length, 0, userdata); + const int ret = handle_packet_connection(c, crypt_connection_id, data, length, 0, userdata); pthread_mutex_lock(&c->tcp_mutex); if (ret != 0) { @@ -2293,7 +2293,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip } pthread_mutex_lock(&c->tcp_mutex); - int ret = add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key); + const int ret = add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key); pthread_mutex_unlock(&c->tcp_mutex); return ret; } @@ -2306,7 +2306,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_key) { pthread_mutex_lock(&c->tcp_mutex); - int ret = add_tcp_relay_global(c->tcp_c, ip_port, public_key); + const int ret = add_tcp_relay_global(c->tcp_c, ip_port, public_key); pthread_mutex_unlock(&c->tcp_mutex); return ret; } @@ -2322,7 +2322,7 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k int get_random_tcp_con_number(Net_Crypto *c) { pthread_mutex_lock(&c->tcp_mutex); - int ret = get_random_tcp_onion_conn_number(c->tcp_c); + const int ret = get_random_tcp_onion_conn_number(c->tcp_c); pthread_mutex_unlock(&c->tcp_mutex); return ret; @@ -2336,7 +2336,7 @@ int get_random_tcp_con_number(Net_Crypto *c) int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length) { pthread_mutex_lock(&c->tcp_mutex); - int ret = tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length); + const int ret = tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length); pthread_mutex_unlock(&c->tcp_mutex); return ret; @@ -2355,7 +2355,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u } pthread_mutex_lock(&c->tcp_mutex); - unsigned int ret = tcp_copy_connected_relays(c->tcp_c, tcp_relays, num); + const unsigned int ret = tcp_copy_connected_relays(c->tcp_c, tcp_relays, num); pthread_mutex_unlock(&c->tcp_mutex); return ret; @@ -2368,7 +2368,7 @@ uint32_t copy_connected_tcp_relays_index(Net_Crypto *c, Node_format *tcp_relays, } pthread_mutex_lock(&c->tcp_mutex); - uint32_t ret = tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx); + const uint32_t ret = tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx); pthread_mutex_unlock(&c->tcp_mutex); return ret; @@ -2616,7 +2616,7 @@ static void send_crypto_packets(Net_Crypto *c) double request_packet_interval = REQUEST_PACKETS_COMPARE_CONSTANT / ((num_packets_array( &conn->recv_array) + 1.0) / (conn->packet_recv_rate + 1.0)); - double request_packet_interval2 = ((CRYPTO_PACKET_MIN_RATE / conn->packet_recv_rate) * + const double request_packet_interval2 = ((CRYPTO_PACKET_MIN_RATE / conn->packet_recv_rate) * (double)CRYPTO_SEND_PACKET_INTERVAL) + (double)PACKET_COUNTER_AVERAGE_INTERVAL; if (request_packet_interval2 < request_packet_interval) { @@ -2649,24 +2649,24 @@ static void send_crypto_packets(Net_Crypto *c) conn->packet_counter = 0; conn->packet_counter_set = temp_time; - uint32_t packets_sent = conn->packets_sent; + const uint32_t packets_sent = conn->packets_sent; conn->packets_sent = 0; - uint32_t packets_resent = conn->packets_resent; + const uint32_t packets_resent = conn->packets_resent; conn->packets_resent = 0; /* conjestion control * calculate a new value of conn->packet_send_rate based on some data */ - unsigned int pos = conn->last_sendqueue_counter % CONGESTION_QUEUE_ARRAY_SIZE; + const unsigned int pos = conn->last_sendqueue_counter % CONGESTION_QUEUE_ARRAY_SIZE; conn->last_sendqueue_size[pos] = num_packets_array(&conn->send_array); long signed int sum = 0; sum = (long signed int)conn->last_sendqueue_size[pos] - (long signed int)conn->last_sendqueue_size[(pos + 1) % CONGESTION_QUEUE_ARRAY_SIZE]; - unsigned int n_p_pos = conn->last_sendqueue_counter % CONGESTION_LAST_SENT_ARRAY_SIZE; + const unsigned int n_p_pos = conn->last_sendqueue_counter % CONGESTION_LAST_SENT_ARRAY_SIZE; conn->last_num_packets_sent[n_p_pos] = packets_sent; conn->last_num_packets_resent[n_p_pos] = packets_resent; @@ -2684,14 +2684,14 @@ static void send_crypto_packets(Net_Crypto *c) // TODO(irungentoo): use real delay unsigned int delay = (unsigned int)(((double)conn->rtt_time / PACKET_COUNTER_AVERAGE_INTERVAL) + 0.5); - unsigned int packets_set_rem_array = CONGESTION_LAST_SENT_ARRAY_SIZE - CONGESTION_QUEUE_ARRAY_SIZE; + const unsigned int packets_set_rem_array = CONGESTION_LAST_SENT_ARRAY_SIZE - CONGESTION_QUEUE_ARRAY_SIZE; if (delay > packets_set_rem_array) { delay = packets_set_rem_array; } for (unsigned j = 0; j < CONGESTION_QUEUE_ARRAY_SIZE; ++j) { - unsigned int ind = (j + (packets_set_rem_array - delay) + n_p_pos) % CONGESTION_LAST_SENT_ARRAY_SIZE; + const unsigned int ind = (j + (packets_set_rem_array - delay) + n_p_pos) % CONGESTION_LAST_SENT_ARRAY_SIZE; total_sent += conn->last_num_packets_sent[ind]; total_resent += conn->last_num_packets_resent[ind]; } @@ -2705,18 +2705,18 @@ static void send_crypto_packets(Net_Crypto *c) } /* if queue is too big only allow resending packets. */ - uint32_t npackets = num_packets_array(&conn->send_array); + const uint32_t npackets = num_packets_array(&conn->send_array); double min_speed = 1000.0 * (((double)total_sent) / ((double)CONGESTION_QUEUE_ARRAY_SIZE * PACKET_COUNTER_AVERAGE_INTERVAL)); - double min_speed_request = 1000.0 * (((double)(total_sent + total_resent)) / ( + const double min_speed_request = 1000.0 * (((double)(total_sent + total_resent)) / ( (double)CONGESTION_QUEUE_ARRAY_SIZE * PACKET_COUNTER_AVERAGE_INTERVAL)); if (min_speed < CRYPTO_PACKET_MIN_RATE) { min_speed = CRYPTO_PACKET_MIN_RATE; } - double send_array_ratio = (double)npackets / min_speed; + const double send_array_ratio = (double)npackets / min_speed; // TODO(irungentoo): Improve formula? if (send_array_ratio > SEND_QUEUE_RATIO && CRYPTO_MIN_QUEUE_LENGTH < npackets) { @@ -2749,8 +2749,8 @@ static void send_crypto_packets(Net_Crypto *c) double n_packets = conn->packet_send_rate * (((double)(temp_time - conn->last_packets_left_set)) / 1000.0); n_packets += conn->last_packets_left_rem; - uint32_t num_packets = n_packets; - double rem = n_packets - (double)num_packets; + const uint32_t num_packets = n_packets; + const double rem = n_packets - (double)num_packets; if (conn->packets_left > num_packets * 4 + CRYPTO_MIN_QUEUE_LENGTH) { conn->packets_left = num_packets * 4 + CRYPTO_MIN_QUEUE_LENGTH; @@ -2781,7 +2781,7 @@ static void send_crypto_packets(Net_Crypto *c) } } - int ret = send_requested_packets(c, i, conn->packets_left_requested); + const int ret = send_requested_packets(c, i, conn->packets_left_requested); if (ret != -1) { conn->packets_left_requested -= ret; @@ -2842,7 +2842,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti return 0; } - uint32_t max_packets = CRYPTO_PACKET_BUFFER_SIZE - num_packets_array(&conn->send_array); + const uint32_t max_packets = CRYPTO_PACKET_BUFFER_SIZE - num_packets_array(&conn->send_array); if (conn->packets_left < max_packets) { return conn->packets_left; @@ -2929,8 +2929,8 @@ int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t return -1; } - uint32_t num = num_packets_array(&conn->send_array); - uint32_t num1 = packet_number - conn->send_array.buffer_start; + const uint32_t num = num_packets_array(&conn->send_array); + const uint32_t num1 = packet_number - conn->send_array.buffer_start; if (num >= num1) { return -1; @@ -2966,8 +2966,8 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t if (conn != nullptr) { pthread_mutex_lock(conn->mutex); - uint32_t buffer_start = conn->recv_array.buffer_start; - uint32_t buffer_end = conn->send_array.buffer_end; + const uint32_t buffer_start = conn->recv_array.buffer_start; + const uint32_t buffer_end = conn->send_array.buffer_end; pthread_mutex_unlock(conn->mutex); ret = send_data_packet_helper(c, crypt_connection_id, buffer_start, buffer_end, data, length); } diff --git a/toxcore/network.c b/toxcore/network.c index 4b7260f8..3272a4ce 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -464,7 +464,7 @@ bool set_socket_dualstack(Socket sock) #else int ipv6only = 0; socklen_t optsize = sizeof(ipv6only); - int res = getsockopt(sock.socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, &optsize); + const int res = getsockopt(sock.socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, &optsize); if ((res == 0) && (ipv6only == 0)) { return true; @@ -506,7 +506,7 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu char ip_str[IP_NTOA_LEN]; if (res < 0) { /* Windows doesn't necessarily know `%zu` */ - int error = net_error(); + const int error = net_error(); char *strerror = net_new_strerror(error); LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x", buffer[0], message, min_u16(buflen, 999), 'E', @@ -660,13 +660,13 @@ static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8 *length = 0; #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - int fail_or_len = fuzz_recvfrom(sock.socket, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); + const int fail_or_len = fuzz_recvfrom(sock.socket, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); #else int fail_or_len = recvfrom(sock.socket, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); #endif if (fail_or_len < 0) { - int error = net_error(); + const int error = net_error(); if (!should_ignore_recv_error(error)) { char *strerror = net_new_strerror(error); @@ -830,7 +830,7 @@ Networking_Core *new_networking_ex(const Logger *log, const IP *ip, uint16_t por } else if (port_from != 0 && port_to == 0) { port_to = port_from; } else if (port_from > port_to) { - uint16_t temp_port = port_from; + const uint16_t temp_port = port_from; port_from = port_to; port_to = temp_port; } @@ -865,7 +865,7 @@ Networking_Core *new_networking_ex(const Logger *log, const IP *ip, uint16_t por /* Check for socket error. */ if (!sock_valid(temp->sock)) { - int neterror = net_error(); + const int neterror = net_error(); char *strerror = net_new_strerror(neterror); LOGGER_ERROR(log, "failed to get a socket?! %d, %s", neterror, strerror); net_kill_strerror(strerror); @@ -1315,8 +1315,8 @@ int addr_resolve(const char *address, IP *to, IP *extra) return 0; } - Family tox_family = to->family; - int family = make_family(tox_family); + const Family tox_family = to->family; + const int family = make_family(tox_family); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); @@ -1595,7 +1595,7 @@ Socket net_socket(Family domain, int type, int protocol) int net_send(const Logger *log, Socket sock, const uint8_t *buf, size_t len, const IP_Port *ip_port) { #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - int res = fuzz_send(sock.socket, (const char *)buf, len, MSG_NOSIGNAL); + const int res = fuzz_send(sock.socket, (const char *)buf, len, MSG_NOSIGNAL); #else int res = send(sock.socket, (const char *)buf, len, MSG_NOSIGNAL); #endif @@ -1606,7 +1606,7 @@ int net_send(const Logger *log, Socket sock, const uint8_t *buf, size_t len, con int net_recv(const Logger *log, Socket sock, uint8_t *buf, size_t len, const IP_Port *ip_port) { #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - int res = fuzz_recv(sock.socket, (char *)buf, len, MSG_NOSIGNAL); + const int res = fuzz_recv(sock.socket, (char *)buf, len, MSG_NOSIGNAL); #else int res = recv(sock.socket, (char *)buf, len, MSG_NOSIGNAL); #endif @@ -1697,8 +1697,8 @@ size_t net_pack_u64(uint8_t *bytes, uint64_t v) size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v) { - uint8_t hi = bytes[0]; - uint8_t lo = bytes[1]; + const uint8_t hi = bytes[0]; + const uint8_t lo = bytes[1]; *v = ((uint16_t)hi << 8) | lo; return sizeof(*v); } diff --git a/toxcore/onion.c b/toxcore/onion.c index 808fc41d..41741a1d 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -65,7 +65,7 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bo memcpy(target->ip.v6.uint8, data + 1, SIZE_IP6); } - bool valid = disable_family_check || + const bool valid = disable_family_check || net_family_is_ipv4(target->family) || net_family_is_ipv6(target->family); @@ -279,7 +279,7 @@ int send_onion_packet(const Networking_Core *net, const Onion_Path *path, const uint16_t length) { uint8_t packet[ONION_MAX_PACKET_SIZE]; - int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); + const int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); if (len == -1) { return -1; @@ -337,7 +337,7 @@ static int handle_send_initial(void *object, const IP_Port *source, const uint8_ uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; get_shared_key(onion->mono_time, &onion->shared_keys_1, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE); - int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, + const int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain); if (len != length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)) { @@ -536,7 +536,7 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT + RETURN_2]; - int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, + const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, SIZE_IPPORT + RETURN_2 + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != sizeof(plain)) { @@ -553,7 +553,7 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac data[0] = NET_PACKET_ONION_RECV_2; memcpy(data + 1, plain + SIZE_IPPORT, RETURN_2); memcpy(data + 1 + RETURN_2, packet + 1 + RETURN_3, length - (1 + RETURN_3)); - uint16_t data_len = 1 + RETURN_2 + (length - (1 + RETURN_3)); + const uint16_t data_len = 1 + RETURN_2 + (length - (1 + RETURN_3)); if ((uint32_t)sendpacket(onion->net, &send_to, data, data_len) != data_len) { return 1; @@ -584,7 +584,7 @@ static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *pac change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT + RETURN_1]; - int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, + const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, SIZE_IPPORT + RETURN_1 + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != sizeof(plain)) { @@ -601,7 +601,7 @@ static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *pac data[0] = NET_PACKET_ONION_RECV_1; memcpy(data + 1, plain + SIZE_IPPORT, RETURN_1); memcpy(data + 1 + RETURN_1, packet + 1 + RETURN_2, length - (1 + RETURN_2)); - uint16_t data_len = 1 + RETURN_1 + (length - (1 + RETURN_2)); + const uint16_t data_len = 1 + RETURN_1 + (length - (1 + RETURN_2)); if ((uint32_t)sendpacket(onion->net, &send_to, data, data_len) != data_len) { return 1; @@ -632,7 +632,7 @@ static int handle_recv_1(void *object, const IP_Port *source, const uint8_t *pac change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT]; - int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, + const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, SIZE_IPPORT + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != SIZE_IPPORT) { @@ -645,7 +645,7 @@ static int handle_recv_1(void *object, const IP_Port *source, const uint8_t *pac return 1; } - uint16_t data_len = length - (1 + RETURN_1); + const uint16_t data_len = length - (1 + RETURN_1); if (onion->recv_1_function != nullptr && !net_family_is_ipv4(send_to.ip.family) && diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 1d51f174..7038e838 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -93,7 +93,7 @@ int create_announce_request(uint8_t *packet, uint16_t max_packet_length, const u packet[0] = NET_PACKET_ANNOUNCE_REQUEST; random_nonce(packet + 1); - int len = encrypt_data(dest_client_id, secret_key, packet + 1, plain, sizeof(plain), + const int len = encrypt_data(dest_client_id, secret_key, packet + 1, plain, sizeof(plain), packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE); if ((uint32_t)len + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE != ONION_ANNOUNCE_REQUEST_SIZE) { @@ -136,7 +136,7 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, const uint8 memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, random_public_key, CRYPTO_PUBLIC_KEY_SIZE); - int len = encrypt_data(encrypt_public_key, random_secret_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length, + const int len = encrypt_data(encrypt_public_key, random_secret_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE); if (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + len != DATA_REQUEST_MIN_SIZE + @@ -417,7 +417,7 @@ static int handle_announce_request(void *object, const IP_Port *source, const ui /*Respond with a announce response packet*/ Node_format nodes_list[MAX_SENT_NODES]; - unsigned int num_nodes = + const unsigned int num_nodes = get_close_nodes(onion_a->dht, plain + ONION_PING_ID_SIZE, nodes_list, net_family_unspec, ip_is_lan(&source->ip)); uint8_t nonce[CRYPTO_NONCE_SIZE]; random_nonce(nonce); @@ -488,7 +488,7 @@ static int handle_data_request(void *object, const IP_Port *source, const uint8_ return 1; } - int index = in_entries(onion_a, packet + 1); + const int index = in_entries(onion_a, packet + 1); if (index == -1) { return 1; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 5893322d..004665a6 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -164,7 +164,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, const IP_Port *ip_port, const memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); - uint16_t last = onion_c->path_nodes_index_bs; + const uint16_t last = onion_c->path_nodes_index_bs; ++onion_c->path_nodes_index_bs; if (onion_c->path_nodes_index_bs < last) { @@ -196,7 +196,7 @@ static int onion_add_path_node(Onion_Client *onion_c, const IP_Port *ip_port, co memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); - uint16_t last = onion_c->path_nodes_index; + const uint16_t last = onion_c->path_nodes_index; ++onion_c->path_nodes_index; if (onion_c->path_nodes_index < last) { @@ -267,7 +267,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format nodes[i] = onion_c->path_nodes[rand_idx]; } } else { - int random_tcp = get_random_tcp_con_number(onion_c->c); + const int random_tcp = get_random_tcp_con_number(onion_c->c); if (random_tcp == -1) { return 0; @@ -338,8 +338,8 @@ static bool path_timed_out(const Mono_Time *mono_time, const Onion_Client_Paths { pathnum = pathnum % NUMBER_ONION_PATHS; - bool is_new = onion_paths->last_path_success[pathnum] == onion_paths->path_creation_time[pathnum]; - uint64_t timeout = is_new ? ONION_PATH_FIRST_TIMEOUT : ONION_PATH_TIMEOUT; + const bool is_new = onion_paths->last_path_success[pathnum] == onion_paths->path_creation_time[pathnum]; + const uint64_t timeout = is_new ? ONION_PATH_FIRST_TIMEOUT : ONION_PATH_TIMEOUT; return ((onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES && mono_time_is_timeout(mono_time, onion_paths->last_path_used[pathnum], timeout)) @@ -380,7 +380,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa return -1; } - int n = is_path_used(onion_c->mono_time, onion_paths, nodes); + const int n = is_path_used(onion_c->mono_time, onion_paths, nodes); if (n == -1) { if (create_onion_path(onion_c->dht, &onion_paths->paths[pathnum], nodes) == -1) { @@ -469,7 +469,7 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa { if (net_family_is_ipv4(path->ip_port1.ip.family) || net_family_is_ipv6(path->ip_port1.ip.family)) { uint8_t packet[ONION_MAX_PACKET_SIZE]; - int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); + const int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); if (len == -1) { return -1; @@ -854,12 +854,12 @@ static int handle_announce_response(void *object, const IP_Port *source, const u return 1; } - uint16_t len_nodes = length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; + const uint16_t len_nodes = length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; IP_Port ip_port; uint32_t path_num; - uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num); + const uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num); if (num > onion_c->num_friends) { return 1; @@ -888,7 +888,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u return 1; } - uint32_t path_used = set_path_timeouts(onion_c, num, path_num); + const uint32_t path_used = set_path_timeouts(onion_c, num, path_num); if (client_add_to_list(onion_c, num, public_key, &ip_port, plain[0], plain + 1, path_used) == -1) { return 1; @@ -896,7 +896,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u if (len_nodes != 0) { Node_format nodes[MAX_SENT_NODES]; - int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0); + const int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0); if (num_nodes <= 0) { return 1; @@ -970,7 +970,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con return 1; } - int friend_num = onion_friend_num(onion_c, source_pubkey); + const int friend_num = onion_friend_num(onion_c, source_pubkey); if (friend_num == -1) { return 1; @@ -993,11 +993,11 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); onion_c->friends_list[friend_num].last_seen = mono_time_get(onion_c->mono_time); - uint16_t len_nodes = length - DHTPK_DATA_MIN_LENGTH; + const uint16_t len_nodes = length - DHTPK_DATA_MIN_LENGTH; if (len_nodes != 0) { Node_format nodes[MAX_SENT_NODES]; - int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE, + const int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE, len_nodes, 1); if (num_nodes <= 0) { @@ -1012,7 +1012,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con } else if (net_family_is_tcp_ipv4(family) || net_family_is_tcp_ipv6(family)) { if (onion_c->friends_list[friend_num].tcp_relay_node_callback != nullptr) { void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; - uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; + const uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, &nodes[i].ip_port, nodes[i].public_key); } } @@ -1186,7 +1186,7 @@ static int handle_dht_dhtpk(void *object, const IP_Port *source, const uint8_t * } uint8_t plain[DHTPK_DATA_MAX_LENGTH]; - int len = decrypt_data(packet, nc_get_self_secret_key(onion_c->c), + const int len = decrypt_data(packet, nc_get_self_secret_key(onion_c->c), packet + CRYPTO_PUBLIC_KEY_SIZE, packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), plain); @@ -1223,7 +1223,7 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8 net_pack_u64(data + 1, no_replay); memcpy(data + 1 + sizeof(uint64_t), dht_get_self_public_key(onion_c->dht), CRYPTO_PUBLIC_KEY_SIZE); Node_format nodes[MAX_SENT_NODES]; - uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, MAX_SENT_NODES / 2); + const uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, MAX_SENT_NODES / 2); uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays); num_nodes += num_relays; int nodes_len = 0; @@ -1310,7 +1310,7 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num) */ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key) { - int num = onion_friend_num(onion_c, public_key); + const int num = onion_friend_num(onion_c, public_key); if (num != -1) { return num; @@ -1524,7 +1524,7 @@ static void populate_path_nodes(Onion_Client *onion_c) { Node_format nodes_list[MAX_FRIEND_CLIENTS]; - unsigned int num_nodes = randfriends_nodes(onion_c->dht, nodes_list, MAX_FRIEND_CLIENTS); + const unsigned int num_nodes = randfriends_nodes(onion_c->dht, nodes_list, MAX_FRIEND_CLIENTS); for (unsigned int i = 0; i < num_nodes; ++i) { onion_add_path_node(onion_c, &nodes_list[i].ip_port, nodes_list[i].public_key); @@ -1536,7 +1536,7 @@ static void populate_path_nodes_tcp(Onion_Client *onion_c) { Node_format nodes_list[MAX_SENT_NODES]; - unsigned int num_nodes = copy_connected_tcp_relays(onion_c->c, nodes_list, MAX_SENT_NODES); + const unsigned int num_nodes = copy_connected_tcp_relays(onion_c->c, nodes_list, MAX_SENT_NODES); for (unsigned int i = 0; i < num_nodes; ++i) { onion_add_bs_path_node(onion_c, &nodes_list[i].ip_port, nodes_list[i].public_key); @@ -1711,7 +1711,7 @@ static void do_announce(Onion_Client *onion_c) if (list_nodes[i].is_stored && path_exists(onion_c->mono_time, &onion_c->onion_paths_self, list_nodes[i].path_used)) { interval = ANNOUNCE_INTERVAL_ANNOUNCED; - uint32_t pathnum = list_nodes[i].path_used % NUMBER_ONION_PATHS; + const uint32_t pathnum = list_nodes[i].path_used % NUMBER_ONION_PATHS; /* A node/path is considered "stable", and can be pinged less * aggressively, if it has survived for at least TIME_TO_STABLE diff --git a/toxcore/tox.c b/toxcore/tox.c index 14fce0af..97a30a12 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -724,7 +724,7 @@ size_t tox_get_savedata_size(const Tox *tox) { assert(tox != nullptr); lock(tox); - size_t ret = 2 * sizeof(uint32_t) + const size_t ret = 2 * sizeof(uint32_t) + messenger_size(tox->m) + conferences_size(tox->m->conferences_object) + end_size(); @@ -937,7 +937,7 @@ uint32_t tox_self_get_nospam(const Tox *tox) { assert(tox != nullptr); lock(tox); - uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); + const uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); unlock(tox); return ret; } @@ -992,7 +992,7 @@ size_t tox_self_get_name_size(const Tox *tox) { assert(tox != nullptr); lock(tox); - size_t ret = m_get_self_name_size(tox->m); + const size_t ret = m_get_self_name_size(tox->m); unlock(tox); return ret; } @@ -1034,7 +1034,7 @@ size_t tox_self_get_status_message_size(const Tox *tox) { assert(tox != nullptr); lock(tox); - size_t ret = m_get_self_statusmessage_size(tox->m); + const size_t ret = m_get_self_statusmessage_size(tox->m); unlock(tox); return ret; } @@ -1226,7 +1226,7 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number) { assert(tox != nullptr); lock(tox); - bool ret = m_friend_exists(tox->m, friend_number); + const bool ret = m_friend_exists(tox->m, friend_number); unlock(tox); return ret; } @@ -1251,7 +1251,7 @@ size_t tox_self_get_friend_list_size(const Tox *tox) { assert(tox != nullptr); lock(tox); - size_t ret = count_friendlist(tox->m); + const size_t ret = count_friendlist(tox->m); unlock(tox); return ret; } @@ -2329,7 +2329,7 @@ size_t tox_conference_get_chatlist_size(const Tox *tox) { assert(tox != nullptr); lock(tox); - size_t ret = count_chatlist(tox->m->conferences_object); + const size_t ret = count_chatlist(tox->m->conferences_object); unlock(tox); return ret; } @@ -2364,7 +2364,7 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t * { assert(tox != nullptr); lock(tox); - bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); + const bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); unlock(tox); return ret; } @@ -2603,7 +2603,7 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) if (tox->m->tcp_server != nullptr) { SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK); - uint16_t ret = tox->m->options.tcp_server_port; + const uint16_t ret = tox->m->options.tcp_server_port; unlock(tox); return ret; } diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 2ffdf447..3b401e9a 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -88,7 +88,7 @@ void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t *d void tox_options_default(struct Tox_Options *options) { if (options != nullptr) { - struct Tox_Options default_options = { 0 }; + const struct Tox_Options default_options = {0}; *options = default_options; tox_options_set_ipv6_enabled(options, true); tox_options_set_udp_enabled(options, true); diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 91b6dbb2..aaa49160 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -222,7 +222,7 @@ bool tox_pass_encrypt(const uint8_t *plaintext, size_t plaintext_len, const uint return false; } - bool result = tox_pass_key_encrypt(key, plaintext, plaintext_len, ciphertext, error); + const bool result = tox_pass_key_encrypt(key, plaintext, plaintext_len, ciphertext, error); tox_pass_key_free(key); return result; } @@ -255,7 +255,7 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t *ciphertext, si ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; ciphertext += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; // salt only affects key derivation - size_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; + const size_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t nonce[crypto_box_NONCEBYTES]; memcpy(nonce, ciphertext, crypto_box_NONCEBYTES); @@ -310,7 +310,7 @@ bool tox_pass_decrypt(const uint8_t *ciphertext, size_t ciphertext_len, const ui return false; } - bool result = tox_pass_key_decrypt(key, ciphertext, ciphertext_len, plaintext, error); + const bool result = tox_pass_key_decrypt(key, ciphertext, ciphertext_len, plaintext, error); tox_pass_key_free(key); return result; }