diff --git a/src/chat_commands.c b/src/chat_commands.c index 8ce9fa8..e2783a2 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -123,7 +123,7 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { - if (num_file_senders >= MAX_FILES) { + if (max_file_senders_index >= (MAX_FILES-1)) { wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n"); return; } @@ -176,14 +176,14 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv file_senders[i].file = file_to_send; file_senders[i].filenum = (uint8_t) filenum; file_senders[i].friendnum = self->num; - file_senders[i].timestamp = (uint64_t)time(NULL); + file_senders[i].timestamp = (uint64_t) time(NULL); file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, self->num), file_to_send); wprintw(window, "Sending file: '%s'\n", path); - if (i == num_file_senders) - ++num_file_senders; + if (i == max_file_senders_index) + ++max_file_senders_index; return; } diff --git a/src/groupchat.c b/src/groupchat.c index cf85899..c945cf0 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -239,10 +239,11 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key) } else /* Add printable chars to buffer and print on input space */ #if HAVE_WIDECHAR - if (iswprint(key)) { + if (iswprint(key)) #else - if (isprint(key)) { + if (isprint(key)) #endif + { if (ctx->pos < (MAX_STR_SIZE-1)) { mvwaddstr(self->window, y, x, wc_to_char(key)); ctx->line[ctx->pos++] = key; diff --git a/src/main.c b/src/main.c index 6ba902b..7f01bfa 100644 --- a/src/main.c +++ b/src/main.c @@ -356,19 +356,19 @@ static void close_file_sender(int i) int j; - for (j = num_file_senders; j > 0; --j) { + for (j = max_file_senders_index; j > 0; --j) { if (file_senders[j-1].active) break; } - num_file_senders = j; + max_file_senders_index = j; } static void do_file_senders(Tox *m) { int i; - for (i = 0; i < num_file_senders; ++i) { + for (i = 0; i < max_file_senders_index; ++i) { if (!file_senders[i].active) continue; @@ -419,9 +419,23 @@ static void do_file_senders(Tox *m) } } +/* This should only be called on exit */ +static void close_file_transfers(Tox *m) +{ + int i; + + for (i = 0; i < max_file_senders_index; ++i) { + if (!file_senders[i].active) + continue; + + fclose(file_senders[i].file); + } +} + void exit_toxic(Tox *m) { store_data(m, DATA_FILE); + close_file_transfers(m); free(DATA_FILE); free(SRVLIST_FILE); free(prompt->stb); diff --git a/src/toxic_windows.h b/src/toxic_windows.h index b81f0d5..27f8c35 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -122,7 +122,7 @@ typedef struct { } FileSender; FileSender file_senders[MAX_FILES]; -uint8_t num_file_senders; +uint8_t max_file_senders_index; typedef struct { uint8_t filenames[MAX_FILES][MAX_STR_SIZE];