Skip to content

Commit

Permalink
Fix a few issues
Browse files Browse the repository at this point in the history
- realloc needs to be error checked
- use correct format specifiers
- make sure optarg and DATA_FILE aren't null before using them
  • Loading branch information
JFreegman committed Nov 2, 2020
1 parent e7a0c32 commit 1bbd50a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/avatars.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int avatar_send(Tox *m, uint32_t friendnum)
}

if (err != TOX_ERR_FILE_SEND_OK) {
fprintf(stderr, "tox_file_send failed for friendnumber %d (error %d)\n", friendnum, err);
fprintf(stderr, "tox_file_send failed for friendnumber %u (error %d)\n", friendnum, err);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
/* transfer is accepted */
if (ft->state == FILE_TRANSFER_PENDING) {
ft->state = FILE_TRANSFER_STARTED;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%d] for '%s' accepted.",
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%zu] for '%s' accepted.",
ft->index, ft->file_name);
char progline[MAX_STR_SIZE];
init_progress_bar(progline);
Expand Down Expand Up @@ -660,7 +660,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
}
}

line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type '/savefile %d' to accept the file transfer.", ft->index);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type '/savefile %zu' to accept the file transfer.", ft->index);

ft->file_size = file_size;
snprintf(ft->file_path, sizeof(ft->file_path), "%s", file_path);
Expand Down
4 changes: 2 additions & 2 deletions src/chat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
return;
}

line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %lu.", groupnum);
}

void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
Expand Down Expand Up @@ -189,7 +189,7 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
goto on_recv_error;
}

line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Saving file [%d] as: '%s'", idx, ft->file_path);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Saving file [%zu] as: '%s'", idx, ft->file_path);

/* prep progress bar line */
char progline[MAX_STR_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion src/friendlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num,
++Friends.num_online;

if (avatar_send(m, num) == -1) {
fprintf(stderr, "avatar_send failed for friend %d\n", num);
fprintf(stderr, "avatar_send failed for friend %u\n", num);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/line_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void line_info_print(ToxWindow *self)
}
}

wprintw(win, "\n", line->msg);
wprintw(win, "\n");
break;

case SYS_MSG:
Expand Down
2 changes: 1 addition & 1 deletion src/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void set_window_title(ToxWindow *self, const char *title, int len)
char cpy[TOXIC_MAX_NAME_LENGTH + 1];

if (self->is_groupchat) { /* keep groupnumber in title */
snprintf(cpy, sizeof(cpy), "%d %s", self->num, title);
snprintf(cpy, sizeof(cpy), "%u %s", self->num, title);
} else {
snprintf(cpy, sizeof(cpy), "%s", title);
}
Expand Down
14 changes: 12 additions & 2 deletions src/term_mplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ static char *read_into_dyn_buffer(FILE *stream)
int length = dyn_buffer_size + strlen(input_ptr);

if (dyn_buffer) {
dyn_buffer = (char *) realloc(dyn_buffer, length);
char *tmp = realloc(dyn_buffer, length);

if (tmp == NULL) {
return NULL;
}

dyn_buffer = tmp;
} else {
dyn_buffer = (char *) malloc(length);
dyn_buffer = malloc(length);

if (dyn_buffer == NULL) {
return NULL;
}
}

strcpy(dyn_buffer + dyn_buffer_size - 1, input_ptr);
Expand Down
10 changes: 9 additions & 1 deletion src/toxic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,23 +1106,31 @@ static void parse_args(int argc, char *argv[])
break;

case 'f':
if (optarg == NULL) {
queue_init_message("Invalid argument for option: %d", opt);
break;
}

arg_opts.use_custom_data = 1;

if (DATA_FILE) {
free(DATA_FILE);
DATA_FILE = NULL;
}

if (BLOCK_FILE) {
free(BLOCK_FILE);
BLOCK_FILE = NULL;
}

DATA_FILE = malloc(strlen(optarg) + 1);
strcpy(DATA_FILE, optarg);

if (DATA_FILE == NULL) {
exit_toxic_err("failed in parse_args", FATALERR_MEMORY);
}

strcpy(DATA_FILE, optarg);

BLOCK_FILE = malloc(strlen(optarg) + strlen("-blocklist") + 1);

if (BLOCK_FILE == NULL) {
Expand Down

0 comments on commit 1bbd50a

Please sign in to comment.