diff --git a/src/chat_commands.c b/src/chat_commands.c index 5d4f43b4c..e15e3bb67 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -107,7 +107,7 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (* return; } - if (!ft) { + if (ft == NULL) { line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid file ID."); return; } @@ -230,7 +230,12 @@ void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char if (argc > 0) { passwd = argv[1]; - passwd_len = strlen(passwd); + passwd_len = (uint16_t) strlen(passwd); + } + + if (passwd_len > TOX_GROUP_MAX_PASSWORD_SIZE) { + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group: Password too long."); + return; } size_t nick_len = tox_self_get_name_size(tox); @@ -244,12 +249,7 @@ void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (const uint8_t *) passwd, passwd_len, &err); if (err != TOX_ERR_GROUP_INVITE_ACCEPT_OK) { - if (err == TOX_ERR_GROUP_INVITE_ACCEPT_TOO_LONG) { - line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group: Password too long."); - } else { - line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); - } - + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); return; } @@ -353,7 +353,7 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*ar FileTransfer *ft = get_file_transfer_struct_index(self->num, idx, FILE_TRANSFER_RECV); - if (!ft) { + if (ft == NULL) { line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "No pending file transfers with ID %ld.", idx); return; } @@ -443,7 +443,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*ar off_t filesize = file_size(path); - if (filesize == 0) { + if (filesize <= 0) { line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid file."); fclose(file_to_send); return; @@ -462,14 +462,14 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*ar FileTransfer *ft = new_file_transfer(self, self->num, filenum, FILE_TRANSFER_SEND, TOX_FILE_KIND_DATA); - if (!ft) { + if (ft == NULL) { err = TOX_ERR_FILE_SEND_TOO_MANY; goto on_send_error; } memcpy(ft->file_name, file_name, namelen + 1); ft->file = file_to_send; - ft->file_size = filesize; + ft->file_size = (uint64_t)filesize; tox_file_get_file_id(tox, self->num, filenum, ft->file_id, NULL); char sizestr[32]; diff --git a/src/conference.h b/src/conference.h index 1076fb3a4..d445302f3 100644 --- a/src/conference.h +++ b/src/conference.h @@ -23,6 +23,8 @@ #ifndef CONFERENCE_H #define CONFERENCE_H +#include + #include "toxic.h" #include "windows.h" diff --git a/src/file_transfers.h b/src/file_transfers.h index f6e0a341f..3e7482d20 100644 --- a/src/file_transfers.h +++ b/src/file_transfers.h @@ -24,6 +24,7 @@ #define FILE_TRANSFERS_H #include +#include #include "notify.h" #include "toxic.h" diff --git a/src/global_commands.c b/src/global_commands.c index b154d0506..a35e19582 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -198,7 +198,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv)[M return; } - id_bin[i] = x; + id_bin[i] = (char) x; } if (friend_is_blocked(id_bin)) { @@ -591,7 +591,7 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv)[ return; } - id_bin[i] = x; + id_bin[i] = (char) x; } const char *passwd = NULL; @@ -599,7 +599,12 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv)[ if (argc > 1) { passwd = argv[2]; - passwd_len = strlen(passwd); + passwd_len = (uint16_t) strlen(passwd); + } + + if (passwd_len > TOX_GROUP_MAX_PASSWORD_SIZE) { + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password length cannot exceed %d.", TOX_GROUP_MAX_PASSWORD_SIZE); + return; } size_t nick_length = tox_self_get_name_size(tox); @@ -612,12 +617,7 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv)[ (const uint8_t *) passwd, passwd_len, &err); if (err != TOX_ERR_GROUP_JOIN_OK) { - if (err == TOX_ERR_GROUP_JOIN_TOO_LONG) { - line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password length cannot exceed %d.", TOX_GROUP_MAX_PASSWORD_SIZE); - } else { - line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); - } - + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); return; } diff --git a/src/groupchat_commands.c b/src/groupchat_commands.c index 2be95e911..b9f132e76 100644 --- a/src/groupchat_commands.c +++ b/src/groupchat_commands.c @@ -200,7 +200,7 @@ void cmd_list(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv)[ { GroupChat *chat = get_groupchat(self->num); - if (!chat) { + if (chat == NULL) { line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object."); return; } @@ -857,7 +857,7 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Tox *tox, int argc, char (*argv) GroupChat *chat = get_groupchat(self->num); - if (!chat) { + if (chat == NULL) { line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object."); return; } diff --git a/src/line_info.h b/src/line_info.h index 64164d5b3..64b5c041f 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -23,6 +23,8 @@ #ifndef LINE_INFO_H #define LINE_INFO_H +#include + #include "toxic.h" #include "windows.h"