From f71f07b0ad4d178c0f25f59872bf22ec80790811 Mon Sep 17 00:00:00 2001 From: AZ Huang Date: Thu, 28 Nov 2013 03:31:10 +0800 Subject: [PATCH] Add extra check to opened file opointer. --- src/chat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chat.c b/src/chat.c index 47a2205..ddc475d 100644 --- a/src/chat.c +++ b/src/chat.c @@ -205,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]; 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) { wattron(ctx->history, COLOR_PAIR(RED)); wprintw(ctx->history, "* Error writing to file.\n");