mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:23:02 +01:00
proper fix for segfault, credit to manuel-arguelles
This commit is contained in:
parent
3d062ca15b
commit
b99ce9ce46
32
src/chat.c
32
src/chat.c
@ -212,10 +212,18 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
wclear(ctx->linewin);
|
wclear(ctx->linewin);
|
||||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
wclrtobot(self->window);
|
wclrtobot(self->window);
|
||||||
|
bool close_win = false;
|
||||||
|
|
||||||
if (line[0] == '/')
|
if (line[0] == '/') {
|
||||||
execute(self, ctx, m, line);
|
if (close_win = !strncmp(line, "/close", strlen("/close"))) {
|
||||||
else {
|
int f_num = ctx->friendnum;
|
||||||
|
delwin(ctx->linewin);
|
||||||
|
del_window(self);
|
||||||
|
disable_chatwin(f_num);
|
||||||
|
} else {
|
||||||
|
execute(self, ctx, m, line);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
/* make sure the string has at least non-space character */
|
/* make sure the string has at least non-space character */
|
||||||
if (!string_is_empty(line)) {
|
if (!string_is_empty(line)) {
|
||||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||||
@ -237,8 +245,13 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->line[0] = L'\0';
|
if (close_win)
|
||||||
ctx->pos = 0;
|
free(ctx);
|
||||||
|
else {
|
||||||
|
ctx->line[0] = L'\0';
|
||||||
|
ctx->pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,13 +381,6 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
|
|||||||
wprintw(ctx->history, "%s\n", id);
|
wprintw(ctx->history, "%s\n", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(cmd, "/close") == 0) {
|
|
||||||
int f_num = ctx->friendnum;
|
|
||||||
delwin(ctx->linewin);
|
|
||||||
del_window(self);
|
|
||||||
disable_chatwin(f_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
wprintw(ctx->history, "Invalid command.\n");
|
wprintw(ctx->history, "Invalid command.\n");
|
||||||
}
|
}
|
||||||
@ -439,7 +445,7 @@ ToxWindow new_chat(Tox *m, int friendnum)
|
|||||||
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
||||||
|
|
||||||
ChatContext *x = calloc(1, sizeof(ChatContext));
|
ChatContext *x = calloc(1, sizeof(ChatContext));
|
||||||
|
ret.x = x;
|
||||||
x->friendnum = friendnum;
|
x->friendnum = friendnum;
|
||||||
ret.x = (void *) x;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,10 @@ int add_window(Tox *m, ToxWindow w)
|
|||||||
void del_window(ToxWindow *w)
|
void del_window(ToxWindow *w)
|
||||||
{
|
{
|
||||||
active_window = windows; // Go to prompt screen
|
active_window = windows; // Go to prompt screen
|
||||||
|
|
||||||
delwin(w->window);
|
delwin(w->window);
|
||||||
w->window = NULL;
|
|
||||||
memset(w, 0, sizeof(ToxWindow));
|
memset(w, 0, sizeof(ToxWindow));
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user