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

array bounds fix

This commit is contained in:
Jfreegman 2014-08-20 13:10:21 -04:00
parent bd20513493
commit f48ec4f49b
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -420,7 +420,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
const char *filename; const char *filename;
char msg[MAX_STR_SIZE] = {0}; char msg[MAX_STR_SIZE] = {0};
int i = 0; /* file_sender index */ int send_idx = 0; /* file sender index */
if (receive_send == 0) { if (receive_send == 0) {
if (!Friends.list[num].file_receiver[filenum].active) if (!Friends.list[num].file_receiver[filenum].active)
@ -428,15 +428,19 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
filename = Friends.list[num].file_receiver[filenum].filename; filename = Friends.list[num].file_receiver[filenum].filename;
} else { } else {
int i;
for (i = 0; i < MAX_FILES; ++i) { for (i = 0; i < MAX_FILES; ++i) {
send_idx = i;
if (file_senders[i].active && file_senders[i].filenum == filenum) if (file_senders[i].active && file_senders[i].filenum == filenum)
break; break;
} }
if (!file_senders[i].active) if (!file_senders[send_idx].active)
return; return;
filename = file_senders[i].filename; filename = file_senders[send_idx].filename;
} }
switch (control_type) { switch (control_type) {
@ -448,7 +452,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
char progline[MAX_STR_SIZE]; char progline[MAX_STR_SIZE];
prep_prog_line(progline); prep_prog_line(progline);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline);
file_senders[i].line_id = self->chatwin->hst->line_end->id + 2; file_senders[send_idx].line_id = self->chatwin->hst->line_end->id + 2;
sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL); sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL);
} }
@ -467,7 +471,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 0) if (receive_send == 0)
chat_close_file_receiver(m, filenum, num, -1); chat_close_file_receiver(m, filenum, num, -1);
else else
close_file_sender(self, m, i, NULL, -1, filenum, num); close_file_sender(self, m, send_idx, NULL, -1, filenum, num);
break; break;
@ -478,7 +482,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_FINISHED); chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_FINISHED);
} else { } else {
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", filename); snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", filename);
close_file_sender(self, m, i, NULL, TOX_FILECONTROL_FINISHED, filenum, num); close_file_sender(self, m, send_idx, NULL, TOX_FILECONTROL_FINISHED, filenum, num);
} }
if (self->active_box != -1) if (self->active_box != -1)
@ -493,7 +497,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 0) if (receive_send == 0)
break; break;
FILE *fp = file_senders[i].file; FILE *fp = file_senders[send_idx].file;
if (fp == NULL) if (fp == NULL)
break; break;
@ -506,7 +510,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
fseek(fp, datapos, SEEK_SET); fseek(fp, datapos, SEEK_SET);
tox_file_send_control(m, num, 0, filenum, TOX_FILECONTROL_ACCEPT, 0, 0); tox_file_send_control(m, num, 0, filenum, TOX_FILECONTROL_ACCEPT, 0, 0);
file_senders[i].noconnection = false; file_senders[send_idx].noconnection = false;
break; break;
} }