mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-27 02:53:27 +01:00
Merge pull request #55 from aitjcize/fix-path-name
Fix trailing slashes which leads to segfault.
This commit is contained in:
commit
7e0bc7768b
10
src/chat.c
10
src/chat.c
@ -109,6 +109,11 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
|
|||||||
|
|
||||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||||
|
|
||||||
|
int idx = strlen(pathname) - 1;
|
||||||
|
while (pathname[idx] == '/') {
|
||||||
|
pathname[idx--] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* try to get file name from path */
|
/* try to get file name from path */
|
||||||
uint8_t *filename = strrchr(pathname, '/'); // Try unix style paths
|
uint8_t *filename = strrchr(pathname, '/'); // Try unix style paths
|
||||||
|
|
||||||
@ -200,6 +205,11 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
|
|||||||
uint8_t *filename = friends[num].file_receiver.filenames[filenum];
|
uint8_t *filename = friends[num].file_receiver.filenames[filenum];
|
||||||
FILE *file_to_save = fopen(filename, "a");
|
FILE *file_to_save = fopen(filename, "a");
|
||||||
|
|
||||||
|
// we have a problem here, but don't let it segfault
|
||||||
|
if (file_to_save == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (fwrite(data, length, 1, file_to_save) != 1) {
|
if (fwrite(data, length, 1, file_to_save) != 1) {
|
||||||
wattron(ctx->history, COLOR_PAIR(RED));
|
wattron(ctx->history, COLOR_PAIR(RED));
|
||||||
wprintw(ctx->history, "* Error writing to file.\n");
|
wprintw(ctx->history, "* Error writing to file.\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user