mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 05:13:02 +01:00
Fix a few issues
- realloc needs to be error checked - use correct format specifiers - make sure optarg and DATA_FILE aren't null before using them
This commit is contained in:
parent
e7a0c32a68
commit
1bbd50aac7
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -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);
|
||||
|
@ -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])
|
||||
@ -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];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ void line_info_print(ToxWindow *self)
|
||||
}
|
||||
}
|
||||
|
||||
wprintw(win, "\n", line->msg);
|
||||
wprintw(win, "\n");
|
||||
break;
|
||||
|
||||
case SYS_MSG:
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
10
src/toxic.c
10
src/toxic.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user