1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 20:03:25 +01:00

fix possible segfaults

This commit is contained in:
Jfreegman 2014-06-18 12:10:00 -04:00
parent bc51714148
commit fc148be3e2
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,7 @@
extern char *DATA_FILE; extern char *DATA_FILE;
extern int store_data(Tox *m, char *path); extern int store_data(Tox *m, char *path);
static GroupChat groupchats[MAX_WINDOWS_NUM]; static GroupChat groupchats[MAX_GROUPCHAT_NUM];
static int max_groupchat_index = 0; static int max_groupchat_index = 0;
extern struct user_settings *user_settings; extern struct user_settings *user_settings;
@ -52,6 +52,9 @@ extern const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum) int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
{ {
if (groupnum > MAX_GROUPCHAT_NUM)
return -1;
int i; int i;
for (i = 0; i <= max_groupchat_index; ++i) { for (i = 0; i <= max_groupchat_index; ++i) {
@ -296,9 +299,15 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
if (self->num != groupnum) if (self->num != groupnum)
return; return;
if (groupnum > MAX_GROUPCHAT_NUM)
return;
groupchats[groupnum].num_peers = tox_group_number_peers(m, groupnum); groupchats[groupnum].num_peers = tox_group_number_peers(m, groupnum);
int num_peers = groupchats[groupnum].num_peers; int num_peers = groupchats[groupnum].num_peers;
if (peernum >= num_peers)
return;
/* get old peer name before updating name list */ /* get old peer name before updating name list */
uint8_t oldpeername[TOX_MAX_NAME_LENGTH]; uint8_t oldpeername[TOX_MAX_NAME_LENGTH];

View File

@ -28,6 +28,7 @@
#define SIDEBAR_WIDTH 16 #define SIDEBAR_WIDTH 16
#define SDBAR_OFST 2 /* Offset for the peer number box at the top of the statusbar */ #define SDBAR_OFST 2 /* Offset for the peer number box at the top of the statusbar */
#define MAX_GROUPCHAT_NUM MAX_WINDOWS_NUM
typedef struct { typedef struct {
int chatwin; int chatwin;