Skip to content

Commit

Permalink
refactor: Allow format strings in fatal error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 18, 2024
1 parent e11f487 commit 3708b1d
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/audio_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static void realloc_calls(uint32_t n)
Call *temp = realloc(CallControl.calls, n * sizeof(Call));

if (temp == NULL) {
exit_toxic_err("failed in realloc_calls", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in realloc_calls");
}

CallControl.calls = temp;
Expand Down
2 changes: 1 addition & 1 deletion src/audio_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ static void *poll_input(void *arg)
int16_t *frame_buf = malloc(FRAME_BUF_SIZE * sizeof(int16_t));

if (frame_buf == NULL) {
exit_toxic_err("failed in thread_poll", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in thread_poll");
}

while (1) {
Expand Down
2 changes: 1 addition & 1 deletion src/autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int complete_line_helper(ToxWindow *self, Toxic *toxic, const char *const
char *sub = calloc(1, strlen(ubuf) + 1);

if (sub == NULL) {
exit_toxic_err("failed in complete_line_helper", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in complete_line_helper");
}

if (!s && !dir_search) {
Expand Down
8 changes: 4 additions & 4 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ static void chat_onInit(ToxWindow *self, Toxic *toxic)
getmaxyx(self->window, y2, x2);

if (y2 <= 0 || x2 <= 0) {
exit_toxic_err("failed in chat_onInit", FATALERR_CURSES);
exit_toxic_err(FATALERR_CURSES, "failed in chat_onInit");
}

self->x = x2;
Expand Down Expand Up @@ -1735,7 +1735,7 @@ static void chat_onInit(ToxWindow *self, Toxic *toxic)
ctx->cqueue = calloc(1, sizeof(struct chat_queue));

if (ctx->log == NULL || ctx->hst == NULL || ctx->cqueue == NULL) {
exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in chat_onInit");
}

line_info_init(ctx->hst);
Expand All @@ -1761,7 +1761,7 @@ ToxWindow *new_chat(Tox *tox, uint32_t friendnum)
ToxWindow *ret = calloc(1, sizeof(ToxWindow));

if (ret == NULL) {
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_chat");
}

ret->type = WINDOW_TYPE_CHAT;
Expand Down Expand Up @@ -1812,7 +1812,7 @@ ToxWindow *new_chat(Tox *tox, uint32_t friendnum)
Help *help = calloc(1, sizeof(Help));

if (stb == NULL || chatwin == NULL || help == NULL) {
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_chat");
}

ret->chatwin = chatwin;
Expand Down
12 changes: 6 additions & 6 deletions src/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static void conference_update_name_list(uint32_t conferencenum)
chat->name_list = malloc(chat->num_peers * sizeof(NameListEntry));

if (chat->name_list == NULL) {
exit_toxic_err("failed in conference_update_name_list", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in conference_update_name_list");
}

uint32_t count = 0;
Expand Down Expand Up @@ -703,7 +703,7 @@ static void update_peer_list(ToxWindow *self, Toxic *toxic, uint32_t conferencen
ConferencePeer *old_peer_list = malloc(old_num_peers * sizeof(ConferencePeer));

if (!old_peer_list) {
exit_toxic_err("failed in update_peer_list", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in update_peer_list");
}

if (chat->peer_list != NULL) {
Expand Down Expand Up @@ -1261,7 +1261,7 @@ static void conference_onInit(ToxWindow *self, Toxic *toxic)
getmaxyx(self->window, y2, x2);

if (x2 <= 0 || y2 <= 0) {
exit_toxic_err("failed in conference_onInit", FATALERR_CURSES);
exit_toxic_err(FATALERR_CURSES, "failed in conference_onInit");
}

ChatContext *ctx = self->chatwin;
Expand All @@ -1275,7 +1275,7 @@ static void conference_onInit(ToxWindow *self, Toxic *toxic)
ctx->log = calloc(1, sizeof(struct chatlog));

if (ctx->log == NULL || ctx->hst == NULL) {
exit_toxic_err("failed in conference_onInit", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in conference_onInit");
}

line_info_init(ctx->hst);
Expand Down Expand Up @@ -1366,7 +1366,7 @@ static ToxWindow *new_conference_chat(uint32_t conferencenum)
ToxWindow *ret = calloc(1, sizeof(ToxWindow));

if (ret == NULL) {
exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_conference_chat");
}

ret->type = WINDOW_TYPE_CONFERENCE;
Expand All @@ -1385,7 +1385,7 @@ static ToxWindow *new_conference_chat(uint32_t conferencenum)
Help *help = calloc(1, sizeof(Help));

if (chatwin == NULL || help == NULL) {
exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_conference_chat");
}

ret->chatwin = chatwin;
Expand Down
2 changes: 1 addition & 1 deletion src/configdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int create_user_config_dirs(char *path)
char *logpath = malloc(strlen(path) + strlen(LOGDIR) + 1);

if (fullpath == NULL || logpath == NULL) {
exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in load_data_structures");
}

strcpy(fullpath, path);
Expand Down
2 changes: 1 addition & 1 deletion src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static int parse_command(const char *input, char (*args)[MAX_STR_SIZE])
char *cmd = strdup(input);

if (cmd == NULL) {
exit_toxic_err("failed in parse_command", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in parse_command");
}

int num_args = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/friendlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void realloc_friends(int n)
uint32_t *f_idx = realloc(Friends.index, n * sizeof(uint32_t));

if (f == NULL || f_idx == NULL) {
exit_toxic_err("failed in realloc_friends", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in realloc_friends");
}

Friends.list = f;
Expand All @@ -118,7 +118,7 @@ static void realloc_blocklist(int n)
uint32_t *b_idx = realloc(Blocked.index, n * sizeof(uint32_t));

if (b == NULL || b_idx == NULL) {
exit_toxic_err("failed in realloc_blocklist", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in realloc_blocklist");
}

Blocked.list = b;
Expand Down Expand Up @@ -1346,7 +1346,7 @@ void friendlist_onInit(ToxWindow *self, Toxic *toxic)
getmaxyx(self->window, y2, x2);

if (y2 <= 0 || x2 <= 0) {
exit_toxic_err("failed in friendlist_onInit", FATALERR_CURSES);
exit_toxic_err(FATALERR_CURSES, "failed in friendlist_onInit");
}

self->window_bar = subwin(self->window, WINDOW_BAR_HEIGHT, x2, y2 - 2, 0);
Expand Down Expand Up @@ -1641,7 +1641,7 @@ ToxWindow *new_friendlist(void)
ToxWindow *ret = calloc(1, sizeof(ToxWindow));

if (ret == NULL) {
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_friendlist");
}

ret->type = WINDOW_TYPE_FRIEND_LIST;
Expand Down Expand Up @@ -1682,7 +1682,7 @@ ToxWindow *new_friendlist(void)
Help *help = calloc(1, sizeof(Help));

if (help == NULL) {
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_friendlist");
}

ret->help = help;
Expand Down
2 changes: 1 addition & 1 deletion src/game_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static void game_onInit(ToxWindow *self, Toxic *toxic)
getmaxyx(self->window, max_y, max_x);

if (max_y <= 0 || max_x <= 0) {
exit_toxic_err("failed in game_onInit", FATALERR_CURSES);
exit_toxic_err(FATALERR_CURSES, "failed in game_onInit");
}

self->window_bar = subwin(self->window, WINDOW_BAR_HEIGHT, max_x, max_y - 2, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/groupchats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ static void groupchat_onInit(ToxWindow *self, Toxic *toxic)
getmaxyx(self->window, y2, x2);

if (x2 <= 0 || y2 <= 0) {
exit_toxic_err("failed in groupchat_onInit", FATALERR_CURSES);
exit_toxic_err(FATALERR_CURSES, "failed in groupchat_onInit");
}

self->x = x2;
Expand All @@ -2282,7 +2282,7 @@ static void groupchat_onInit(ToxWindow *self, Toxic *toxic)
ctx->log = calloc(1, sizeof(struct chatlog));

if (ctx->log == NULL || ctx->hst == NULL) {
exit_toxic_err("failed in groupchat_onInit", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in groupchat_onInit");
}

line_info_init(ctx->hst);
Expand Down Expand Up @@ -2344,7 +2344,7 @@ static ToxWindow *new_group_chat(Tox *tox, uint32_t groupnumber, const char *gro
ToxWindow *ret = calloc(1, sizeof(ToxWindow));

if (ret == NULL) {
exit_toxic_err("failed in new_group_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_group_chat");
}

ret->type = WINDOW_TYPE_GROUPCHAT;
Expand Down Expand Up @@ -2373,7 +2373,7 @@ static ToxWindow *new_group_chat(Tox *tox, uint32_t groupnumber, const char *gro
Help *help = calloc(1, sizeof(Help));

if (stb == NULL || chatwin == NULL || help == NULL) {
exit_toxic_err("failed in new_group_chat", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in new_group_chat");
}

ret->chatwin = chatwin;
Expand Down
4 changes: 2 additions & 2 deletions src/line_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void line_info_init(struct history *hst)
hst->line_root = calloc(1, sizeof(struct line_info));

if (hst->line_root == NULL) {
exit_toxic_err("failed in line_info_init", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in line_info_init");
}

hst->line_start = hst->line_root;
Expand Down Expand Up @@ -412,7 +412,7 @@ int line_info_add(ToxWindow *self, const Client_Config *c_config, bool show_time
struct line_info *new_line = calloc(1, sizeof(struct line_info));

if (new_line == NULL) {
exit_toxic_err("failed in line_info_add", FATALERR_MEMORY);
exit_toxic_err(FATALERR_MEMORY, "failed in line_info_add");
}

char frmt_msg[MAX_LINE_INFO_MSG_SIZE];
Expand Down
Loading

0 comments on commit 3708b1d

Please sign in to comment.