mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 13:13:24 +01:00
added infinite loop check
This commit is contained in:
parent
c08639b8e1
commit
4f2e80ef28
@ -10,6 +10,7 @@
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
@ -61,7 +62,7 @@ void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t
|
||||
|
||||
int friendlist_onFriendAdded(Tox *m, int num)
|
||||
{
|
||||
if (num_friends == MAX_FRIENDS_NUM)
|
||||
if (num_friends < 0 || num_friends >= MAX_FRIENDS_NUM)
|
||||
return -1;
|
||||
|
||||
int i;
|
||||
@ -91,15 +92,19 @@ static void select_friend(wint_t key)
|
||||
return;
|
||||
|
||||
int n = num_selected;
|
||||
int f_inf = num_selected;
|
||||
|
||||
if (key == KEY_UP) {
|
||||
while (true) {
|
||||
if (--n < 0)
|
||||
n = num_friends-1;
|
||||
if (--n < 0) n = num_friends-1;
|
||||
if (friends[n].active) {
|
||||
num_selected = n;
|
||||
return;
|
||||
}
|
||||
if (n == f_inf) {
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
} else if (key == KEY_DOWN) {
|
||||
while (true) {
|
||||
@ -108,6 +113,10 @@ static void select_friend(wint_t key)
|
||||
num_selected = n;
|
||||
return;
|
||||
}
|
||||
if (n == f_inf) {
|
||||
endwin();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,7 +129,7 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
|
||||
|
||||
int i;
|
||||
|
||||
for (i = num_friends; i != 0; --i) {
|
||||
for (i = num_friends; i > 0; --i) {
|
||||
if (friends[i-1].active)
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user