Skip to content

Commit

Permalink
cleanup: Add and fix -Wformat-nonliteral
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Feb 8, 2024
1 parent f4f7f00 commit 568bf99
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 41 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 -Wcast-align -Wcast-qual -Wmissing-declarations -Wshadow -Wunused-macros
CFLAGS ?= -std=c11 -pthread -Wall -Wpedantic -Wunused -fstack-protector-all -Wvla -Wno-missing-braces -Wmissing-prototypes -Wcast-align -Wcast-qual -Wmissing-declarations -Wshadow -Wunused-macros -Wformat-nonliteral
CFLAGS += '-DTOXICVER="$(VERSION)"' -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED -D_FILE_OFFSET_BITS=64
CFLAGS += '-DPACKAGE_DATADIR="$(abspath $(DATADIR))"'
CFLAGS += ${USER_CFLAGS}
Expand Down
11 changes: 5 additions & 6 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void api_display(const char *const msg)
}

self_window = get_active_window();
line_info_add(self_window, user_toxic->c_config, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self_window, user_toxic->c_config, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
}

FriendsList api_get_friendslist(void)
Expand Down Expand Up @@ -145,28 +145,27 @@ void cmd_run(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg
const Client_Config *c_config = toxic->c_config;

FILE *fp;
const char *error_str;

cur_window = window;
self_window = self;

if (argc != 1) {
const char *error_str;

if (argc < 1) {
error_str = "Path must be specified.";
} else {
error_str = "Only one argument allowed.";
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
return;
}

fp = fopen(argv[1], "r");

if (fp == NULL) {
error_str = "Path does not exist.";

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Path does not exist.");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static void chat_onConnectionChange(ToxWindow *self, Toxic *toxic, uint32_t num,
file_send_queue_check(self, toxic, self->num);

msg = "has come online";
line_info_add(self, c_config, true, nick, NULL, CONNECTION, 0, GREEN, msg);
line_info_add(self, c_config, true, nick, NULL, CONNECTION, 0, GREEN, "%s", msg);
write_to_log(ctx->log, c_config, msg, nick, true);
} else if (connection_status == TOX_CONNECTION_NONE) {
Friends.list[num].is_typing = false;
Expand All @@ -289,7 +289,7 @@ static void chat_onConnectionChange(ToxWindow *self, Toxic *toxic, uint32_t num,
chat_pause_file_transfers(num);

msg = "has gone offline";
line_info_add(self, c_config, true, nick, NULL, DISCONNECTION, 0, RED, msg);
line_info_add(self, c_config, true, nick, NULL, DISCONNECTION, 0, RED, "%s", msg);
write_to_log(ctx->log, c_config, msg, nick, true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/chat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void cmd_autoaccept_files(WINDOW *window, ToxWindow *self, Toxic *toxic, int arg
msg = "Auto-file accept for this friend is disabled; type \"/autoaccept on\" to enable";
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
return;
}

Expand All @@ -74,7 +74,7 @@ void cmd_autoaccept_files(WINDOW *window, ToxWindow *self, Toxic *toxic, int arg
msg = "Invalid option. Use \"/autoaccept on\" and \"/autoaccept off\" to toggle auto-file accept";
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
}

void cmd_cancelfile(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
Expand Down
6 changes: 3 additions & 3 deletions src/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ static void update_peer_list(ToxWindow *self, Toxic *toxic, uint32_t conferencen

if (new_peer && peer->name_length > 0 && timed_out(chat->start_time, CONFERENCE_EVENT_WAIT)) {
const char *msg = "has joined the conference";
line_info_add(self, c_config, true, peer->name, NULL, CONNECTION, 0, GREEN, msg);
line_info_add(self, c_config, true, peer->name, NULL, CONNECTION, 0, GREEN, "%s", msg);
write_to_log(ctx->log, c_config, msg, peer->name, true);
}

Expand All @@ -770,7 +770,7 @@ static void update_peer_list(ToxWindow *self, Toxic *toxic, uint32_t conferencen
if (old_peer->active) {
if (old_peer->name_length > 0 && !find_peer_by_pubkey(chat->peer_list, chat->num_peers, old_peer->pubkey, NULL)) {
const char *msg = "has left the conference";
line_info_add(self, c_config, true, old_peer->name, NULL, DISCONNECTION, 0, RED, msg);
line_info_add(self, c_config, true, old_peer->name, NULL, DISCONNECTION, 0, RED, "%s", msg);
write_to_log(ctx->log, c_config, msg, old_peer->name, true);
}

Expand Down Expand Up @@ -850,7 +850,7 @@ static void conference_onConferencePeerNameChange(ToxWindow *self, Toxic *toxic,
// this is kind of a hack; peers always join a group with no name set and then set it after
} else if (timed_out(conferences[conferencenum].start_time, CONFERENCE_EVENT_WAIT)) {
const char *msg = "has joined the conference";
line_info_add(self, c_config, true, name, NULL, CONNECTION, 0, GREEN, msg);
line_info_add(self, c_config, true, name, NULL, CONNECTION, 0, GREEN, "%s", msg);
write_to_log(ctx->log, c_config, msg, name, true);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/friendlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,7 @@ static bool friendlist_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr
Friends.list[f].chatwin = add_window(toxic, new_chat(tox, Friends.list[f].num));
set_active_window_index(Friends.list[f].chatwin);
} else {
const char *msg = "* Warning: Too many windows are open.";
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, msg);
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, "* Warning: Too many windows are open.");
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

Expand Down Expand Up @@ -1465,8 +1464,7 @@ static void friendlist_onAV(ToxWindow *self, Toxic *toxic, uint32_t friend_numbe
get_nick_truncate(tox, nick, Friends.list[friend_number].num);
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick);

const char *errmsg = "* Warning: Too many windows are open.";
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, errmsg);
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, "* Warning: Too many windows are open.");

sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}
Expand Down
26 changes: 12 additions & 14 deletions src/global_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void cmd_add_helper(ToxWindow *self, Toxic *toxic, const char *id_bin, const cha
break;
}

line_info_add(self, toxic->c_config, false, NULL, NULL, SYS_MSG, 0, 0, errmsg);
line_info_add(self, toxic->c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", errmsg);
}

void cmd_add(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
Expand Down Expand Up @@ -719,17 +719,18 @@ void cmd_log(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg

const Client_Config *c_config = toxic->c_config;

const char *msg;
struct chatlog *log = self->chatwin->log;

if (argc == 0) {
const char *msg;

if (log->log_on) {
msg = "Logging for this window is ON; type \"/log off\" to disable. (Logs are not encrypted)";
} else {
msg = "Logging for this window is OFF; type \"/log on\" to enable.";
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
return;
}

Expand All @@ -739,7 +740,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg
if (log_enable(log) == 0) {
char e_msg[MAX_STR_SIZE];
snprintf(e_msg, sizeof(e_msg), "Logging to: %s", log->path);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, e_msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", e_msg);
return;
}

Expand All @@ -754,13 +755,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg

log_disable(log);

msg = "Logging disabled.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Logging disabled.");
return;
}

msg = "Invalid option. Use \"/log on\" and \"/log off\" to toggle logging.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0,
"Invalid option. Use \"/log on\" and \"/log off\" to toggle logging.");
}

void cmd_myid(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
Expand Down Expand Up @@ -1052,13 +1052,11 @@ void cmd_status(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*
Tox *tox = toxic->tox;
const Client_Config *c_config = toxic->c_config;

const char *errmsg = NULL;

lock_status();

if (argc < 1) {
errmsg = "Require a status. Statuses are: online, busy and away.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, errmsg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0,
"Require a status. Statuses are: online, busy and away.");
goto finish;
}

Expand All @@ -1072,8 +1070,8 @@ void cmd_status(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*
} else if (!strcasecmp(status_str, "busy")) {
status = TOX_USER_STATUS_BUSY;
} else {
errmsg = "Invalid status. Valid statuses are: online, busy and away.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, errmsg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0,
"Invalid status. Valid statuses are: online, busy and away.");
goto finish;
}

Expand Down
1 change: 1 addition & 0 deletions src/line_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct history {
* Returns the id of the new line.
* Returns -1 on failure.
*/
__attribute__((format(printf, 9, 10)))
int line_info_add(ToxWindow *self, const Client_Config *c_config, bool show_timestamp, const char *name1,
const char *name2, LINE_TYPE type, uint8_t bold, uint8_t colour, const char *msg, ...);

Expand Down
1 change: 1 addition & 0 deletions src/name_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static void clear_thread_data(void)
};
}

__attribute__((format(printf, 3, 4)))
static int lookup_error(ToxWindow *self, const Client_Config *c_config, const char *errmsg, ...)
{
char frmt_msg[MAX_STR_SIZE];
Expand Down
4 changes: 4 additions & 0 deletions src/notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ int sound_notify2(ToxWindow *self, const Toxic *toxic, Notification notif, uint6

void stop_sound(int id);

__attribute__((format(printf, 7, 8)))
int box_notify(ToxWindow *self, const Toxic *toxic, Notification notif, uint64_t flags,
int *id_indicator,
const char *title, const char *format, ...);
__attribute__((format(printf, 6, 7)))
int box_notify2(ToxWindow *self, const Toxic *toxic, Notification notif, uint64_t flags, int id,
const char *format, ...);
__attribute__((format(printf, 6, 7)))
int box_silent_notify(ToxWindow *self, const Toxic *toxic, uint64_t flags, int *id_indicator,
const char *title, const char *format, ...);
__attribute__((format(printf, 5, 6)))
int box_silent_notify2(ToxWindow *self, const Toxic *toxic, uint64_t flags, int id,
const char *format, ...);

Expand Down
15 changes: 7 additions & 8 deletions src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Toxic *toxic, uint32_t fr

if (connection_status != TOX_CONNECTION_NONE && Friends.list[friendnum].connection_status == TOX_CONNECTION_NONE) {
msg = "has come online";
line_info_add(self, c_config, true, nick, NULL, CONNECTION, 0, GREEN, msg);
line_info_add(self, c_config, true, nick, NULL, CONNECTION, 0, GREEN, "%s", msg);
write_to_log(ctx->log, c_config, msg, nick, true);

if (self->active_box != -1) {
Expand All @@ -532,7 +532,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Toxic *toxic, uint32_t fr
}
} else if (connection_status == TOX_CONNECTION_NONE) {
msg = "has gone offline";
line_info_add(self, c_config, true, nick, NULL, DISCONNECTION, 0, RED, msg);
line_info_add(self, c_config, true, nick, NULL, DISCONNECTION, 0, RED, "%s", msg);
write_to_log(ctx->log, c_config, msg, nick, true);

if (self->active_box != -1) {
Expand Down Expand Up @@ -589,8 +589,7 @@ static void prompt_onFriendRequest(ToxWindow *self, Toxic *toxic, const char *ke
const int n = add_friend_request(key, data);

if (n == -1) {
const char *errmsg = "Friend request queue is full. Discarding request.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, errmsg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Friend request queue is full. Discarding request.");
return;
}

Expand Down Expand Up @@ -660,10 +659,10 @@ static void print_welcome_msg(ToxWindow *self, const Client_Config *c_config)
" |_| \\___/_/\\_\\___\\____| v." TOXICVER);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "");

const char *msg = "Welcome to Toxic, a free, open source Tox-based instant messaging client.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 1, CYAN, msg);
msg = "Type \"/help\" for assistance. Further help may be found via the man page.";
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 1, CYAN, msg);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 1, CYAN,
"Welcome to Toxic, a free, open source Tox-based instant messaging client.");
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 1, CYAN,
"Type \"/help\" for assistance. Further help may be found via the man page.");
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "");
}

Expand Down
3 changes: 2 additions & 1 deletion src/toxic.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ static struct _init_messages {
} init_messages;

/* One-time queue for messages created during init. Do not use after program init. */
__attribute__((format(printf, 1, 2)))
static void queue_init_message(const char *msg, ...)
{
char frmt_msg[MAX_STR_SIZE] = {0};
Expand Down Expand Up @@ -528,7 +529,7 @@ static void cleanup_init_messages(void)
static void print_init_messages(ToxWindow *home_window, const Client_Config *c_config)
{
for (int i = 0; i < init_messages.num; ++i) {
line_info_add(home_window, c_config, NULL, NULL, NULL, SYS_MSG, 0, 0, init_messages.msgs[i]);
line_info_add(home_window, c_config, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", init_messages.msgs[i]);
}
}

Expand Down

0 comments on commit 568bf99

Please sign in to comment.