Skip to content

Commit

Permalink
cleanup: add cast-align and cast-qual compile flags and clean up warn…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
JFreegman committed Feb 4, 2024
1 parent 0d5880b commit afce6b3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CFG_DIR = $(BASE_DIR)/cfg

LIBS = toxcore ncursesw libconfig libcurl

CFLAGS ?= -std=c11 -pthread -Wall -Wpedantic -Wunused -fstack-protector-all -Wvla -Wno-missing-braces -Wmissing-prototypes
CFLAGS ?= -std=c11 -pthread -Wall -Wpedantic -Wunused -fstack-protector-all -Wvla -Wno-missing-braces -Wmissing-prototypes -Wcast-align -Wcast-qual
CFLAGS += '-DTOXICVER="$(VERSION)"' -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED -D_FILE_OFFSET_BITS=64
CFLAGS += '-DPACKAGE_DATADIR="$(abspath $(DATADIR))"'
CFLAGS += ${USER_CFLAGS}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ static void *load_nodeslist_thread(void *data)
* Return -4 if pthread fails to set detached state.
* Return -5 if thread creation fails.
*/
int load_DHT_nodeslist(const Toxic *toxic)
int load_DHT_nodeslist(Toxic *toxic)
{
if (thread_data.active) {
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ void do_tox_connection(Toxic *toxic);
* Return -4 if pthread fails to set detached state.
* Return -5 if thread creation fails.
*/
int load_DHT_nodeslist(const Toxic *toxic);
int load_DHT_nodeslist(Toxic *toxic);

#endif /* BOOTSTRAP_H */
4 changes: 2 additions & 2 deletions src/groupchat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void cmd_set_passwd(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, cha
}

Tox_Err_Group_Founder_Set_Password err;
tox_group_founder_set_password(toxic->tox, self->num, (uint8_t *) passwd, len, &err);
tox_group_founder_set_password(toxic->tox, self->num, (const uint8_t *) passwd, len, &err);

switch (err) {
case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK: {
Expand Down Expand Up @@ -936,7 +936,7 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char
const char *topic = argv[1];

Tox_Err_Group_Topic_Set err;
tox_group_set_topic(tox, self->num, (uint8_t *) topic, strlen(topic), &err);
tox_group_set_topic(tox, self->num, (const uint8_t *) topic, strlen(topic), &err);

switch (err) {
case TOX_ERR_GROUP_TOPIC_SET_OK: {
Expand Down
16 changes: 8 additions & 8 deletions src/groupchats.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void exit_groupchat(ToxWindow *self, Toxic *toxic, uint32_t groupnumber, const c
length = TOX_GROUP_MAX_PART_LENGTH;
}

tox_group_leave(toxic->tox, groupnumber, (uint8_t *) partmessage, length, NULL);
tox_group_leave(toxic->tox, groupnumber, (const uint8_t *) partmessage, length, NULL);

if (self != NULL) {
close_groupchat(self, toxic, groupnumber);
Expand Down Expand Up @@ -433,7 +433,7 @@ void set_nick_this_group(ToxWindow *self, Toxic *toxic, const char *new_nick, si
size_t old_length = get_group_self_nick_truncate(tox, old_nick, self->num);

Tox_Err_Group_Self_Name_Set err;
tox_group_self_set_name(tox, self->num, (uint8_t *) new_nick, length, &err);
tox_group_self_set_name(tox, self->num, (const uint8_t *) new_nick, length, &err);

GroupChat *chat = get_groupchat(self->num);

Expand Down Expand Up @@ -520,7 +520,7 @@ void set_status_all_groups(Toxic *toxic, uint8_t status)

/* Returns a weight for peer_sort_cmp based on the peer's role. */
#define PEER_CMP_BASE_WEIGHT 100000
static int peer_sort_cmp_weight(struct GroupPeer *peer)
static int peer_sort_cmp_weight(const struct GroupPeer *peer)
{
int w = PEER_CMP_BASE_WEIGHT;

Expand All @@ -537,8 +537,8 @@ static int peer_sort_cmp_weight(struct GroupPeer *peer)

static int peer_sort_cmp(const void *n1, const void *n2)
{
struct GroupPeer *peer1 = (struct GroupPeer *) n1;
struct GroupPeer *peer2 = (struct GroupPeer *) n2;
const struct GroupPeer *peer1 = (const struct GroupPeer *) n1;
const struct GroupPeer *peer2 = (const struct GroupPeer *) n2;

int res = qsort_strcasecmp_hlpr(peer1->name, peer2->name);
return res - peer_sort_cmp_weight(peer1) + peer_sort_cmp_weight(peer2);
Expand Down Expand Up @@ -1739,7 +1739,7 @@ static void send_group_message(ToxWindow *self, Toxic *toxic, uint32_t groupnumb
}

Tox_Err_Group_Send_Message err;
tox_group_send_message(tox, groupnumber, type, (uint8_t *) msg, strlen(msg), &err);
tox_group_send_message(tox, groupnumber, type, (const uint8_t *) msg, strlen(msg), &err);

if (err != TOX_ERR_GROUP_SEND_MESSAGE_OK) {
if (err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS) {
Expand Down Expand Up @@ -1836,7 +1836,7 @@ static void send_group_prvt_message(ToxWindow *self, Toxic *toxic, uint32_t grou
Tox_Err_Group_Send_Private_Message err;

if (!tox_group_send_private_message(toxic->tox, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL,
(uint8_t *) msg, msg_len, &err)) {
(const uint8_t *) msg, msg_len, &err)) {
if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) {
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced.");
} else {
Expand Down Expand Up @@ -1913,7 +1913,7 @@ static bool groupchat_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr)

/* TODO: make this not suck */
if (ctx->line[0] != L'/' || wcschr(ctx->line, L' ') != NULL) {
diff = complete_line(self, toxic, (const char **) chat->name_list, chat->num_peers);
diff = complete_line(self, toxic, (const char *const *) chat->name_list, chat->num_peers);
} else if (wcsncmp(ctx->line, L"/avatar \"", wcslen(L"/avatar \"")) == 0) {
diff = dir_match(self, toxic, ctx->line, L"/avatar");
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/term_mplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static void mplex_timer_handler(Toxic *toxic)
/* Time in seconds between calls to mplex_timer_handler */
#define MPLEX_TIMER_INTERVAL 5

static void *mplex_timer_thread(void *data)
_Noreturn static void *mplex_timer_thread(void *data)
{
Toxic *toxic = (Toxic *) data;

Expand Down
8 changes: 4 additions & 4 deletions src/toxic.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ int store_data(const Toxic *toxic)
}

Tox_Err_Encryption err;
tox_pass_encrypt((uint8_t *) data, data_len, (uint8_t *) toxic->client_data.pass,
tox_pass_encrypt((uint8_t *) data, data_len, (const uint8_t *) toxic->client_data.pass,
toxic->client_data.pass_len, (uint8_t *) enc_data, &err);

if (err != TOX_ERR_ENCRYPTION_OK) {
Expand Down Expand Up @@ -1273,7 +1273,7 @@ static void *thread_winref(void *data)
}
}

static void *thread_cqueue(void *data)
_Noreturn static void *thread_cqueue(void *data)
{
Toxic *toxic = (Toxic *) data;

Expand All @@ -1299,7 +1299,7 @@ static void *thread_cqueue(void *data)
}

#ifdef AUDIO
static void *thread_av(void *data)
_Noreturn static void *thread_av(void *data)
{
ToxAV *av = (ToxAV *) data;

Expand All @@ -1308,7 +1308,7 @@ static void *thread_av(void *data)
toxav_iterate(av);
pthread_mutex_unlock(&Winthread.lock);

long int sleep_duration = toxav_iteration_interval(av) * 1000;
const long int sleep_duration = toxav_iteration_interval(av) * 1000;
sleep_thread(sleep_duration);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ void on_group_invite(Tox *tox, uint32_t friendnumber, const uint8_t *invite_data

for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i] != NULL && windows[i]->onGroupInvite != NULL) {
windows[i]->onGroupInvite(windows[i], toxic, friendnumber, (char *) invite_data, length, gname, group_name_length);
windows[i]->onGroupInvite(windows[i], toxic, friendnumber, (const char *) invite_data, length, gname,
group_name_length);
}
}
}
Expand Down Expand Up @@ -569,7 +570,7 @@ void on_group_password(Tox *tox, uint32_t groupnumber, const uint8_t *password,

for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i] != NULL && windows[i]->onGroupPassword != NULL) {
windows[i]->onGroupPassword(windows[i], toxic, groupnumber, (char *) password, length);
windows[i]->onGroupPassword(windows[i], toxic, groupnumber, (const char *) password, length);
}
}
}
Expand Down

0 comments on commit afce6b3

Please sign in to comment.