Skip to content

Commit

Permalink
cleanup: make all command related files conform to tokstyle's check-c…
Browse files Browse the repository at this point in the history
… tool
  • Loading branch information
JFreegman committed Jan 18, 2024
1 parent 0f410ef commit 8bf0709
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
24 changes: 12 additions & 12 deletions src/chat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions src/conference.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef CONFERENCE_H
#define CONFERENCE_H

#include <time.h>

#include "toxic.h"
#include "windows.h"

Expand Down
1 change: 1 addition & 0 deletions src/file_transfers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define FILE_TRANSFERS_H

#include <limits.h>
#include <time.h>

#include "notify.h"
#include "toxic.h"
Expand Down
18 changes: 9 additions & 9 deletions src/global_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -591,15 +591,20 @@ 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;
uint16_t passwd_len = 0;

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);
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/groupchat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/line_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef LINE_INFO_H
#define LINE_INFO_H

#include <time.h>

#include "toxic.h"
#include "windows.h"

Expand Down

0 comments on commit 8bf0709

Please sign in to comment.