1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-06 09:26:44 +02:00

more thorough error checking

This commit is contained in:
Jfreegman
2014-09-23 22:51:56 -04:00
parent 48cf4ebf02
commit b071a9e992
11 changed files with 93 additions and 23 deletions

View File

@ -224,9 +224,25 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
return;
}
fseek(file_to_send, 0, SEEK_END);
if (fseek(file_to_send, 0, SEEK_END) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File corrupt.");
fclose(file_to_send);
return;
}
uint64_t filesize = ftell(file_to_send);
fseek(file_to_send, 0, SEEK_SET);
if (filesize == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File corrupt.");
fclose(file_to_send);
return;
}
if (fseek(file_to_send, 0, SEEK_SET) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File corrupt.");
fclose(file_to_send);
return;
}
char filename[MAX_STR_SIZE] = {0};
get_file_name(filename, sizeof(filename), path);
@ -235,6 +251,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if (filenum == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error sending file.");
fclose(file_to_send);
return;
}