1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:53:26 +01:00

fix potential segfaults

This commit is contained in:
Jfreegman 2014-03-27 23:13:38 -04:00
parent b36a8fd8fa
commit 8c071fb208
2 changed files with 13 additions and 11 deletions

View File

@ -321,7 +321,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
/* refresh line with percentage complete */ /* refresh line with percentage complete */
uint8_t msg[MAX_STR_SIZE]; uint8_t msg[MAX_STR_SIZE];
uint64_t size = friends[num].file_receiver.size[filenum]; uint64_t size = friends[num].file_receiver.size[filenum];
long double remain = (double) tox_file_data_remaining(m, num, filenum, 1); long double remain = (long double) tox_file_data_remaining(m, num, filenum, 1);
long double pct_remain = 100; long double pct_remain = 100;
if (remain) if (remain)

View File

@ -78,7 +78,7 @@ void do_file_senders(Tox *m)
/* If file transfer has timed out kill transfer and send kill control */ /* If file transfer has timed out kill transfer and send kill control */
if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) { if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) {
if (self->chatwin->history != NULL) { if (self->chatwin != NULL) {
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", pathname); snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", pathname);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true); alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true);
@ -99,19 +99,21 @@ void do_file_senders(Tox *m)
tox_file_data_size(m, friendnum), fp); tox_file_data_size(m, friendnum), fp);
/* refresh line with percentage complete */ /* refresh line with percentage complete */
uint64_t size = file_senders[i].size; if (self->chatwin != NULL) {
long double remain = (double) tox_file_data_remaining(m, friendnum, filenum, 0); uint64_t size = file_senders[i].size;
long double pct_remain = 100; long double remain = (long double) tox_file_data_remaining(m, friendnum, filenum, 0);
long double pct_remain = 100;
if (remain) if (remain)
pct_remain = (1 - (remain / size)) * 100; pct_remain = (1 - (remain / size)) * 100;
const uint8_t *name = file_senders[filenum].pathname; const uint8_t *name = file_senders[filenum].pathname;
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1Lf%%)", name, pct_remain); snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1Lf%%)", name, pct_remain);
line_info_set(self, file_senders[filenum].line_id, msg); line_info_set(self, file_senders[filenum].line_id, msg);
}
if (file_senders[i].piecelen == 0) { if (file_senders[i].piecelen == 0) {
if (self->chatwin->history != NULL) { if (self->chatwin != NULL) {
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", pathname); snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", pathname);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true); alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true);