mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 04:53:02 +01:00
Fix a bunch of misc bugs and corner cases
This commit is contained in:
parent
14a8bdb874
commit
fa0e645a79
@ -169,8 +169,9 @@ void terminate_audio()
|
||||
void read_device_callback(const int16_t* captured, uint32_t size, void* data)
|
||||
{
|
||||
TOXAV_ERR_SEND_FRAME error;
|
||||
uint32_t friend_number = *((uint32_t*)data); /* TODO: Or pass an array of call_idx's */
|
||||
int64_t sample_count = CallControl.audio_sample_rate * CallControl.audio_frame_duration / 1000;
|
||||
uint32_t friend_number = *((uint32_t *)data); /* TODO: Or pass an array of call_idx's */
|
||||
int64_t sample_count = ((int64_t) CallControl.audio_sample_rate) * \
|
||||
((int64_t) CallControl.audio_frame_duration) / 1000;
|
||||
|
||||
if ( sample_count <= 0 || toxav_audio_send_frame(CallControl.av, friend_number,
|
||||
captured, sample_count,
|
||||
|
@ -114,7 +114,7 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
|
||||
tmp[ctx->pos] = '\0';
|
||||
|
||||
const char *s = dir_search ? strchr(tmp, '\"') : strrchr(tmp, ' ');
|
||||
char *sub = malloc(strlen(ubuf) + 1);
|
||||
char *sub = calloc(1, strlen(ubuf) + 1);
|
||||
|
||||
if (sub == NULL)
|
||||
exit_toxic_err("failed in complete_line", FATALERR_MEMORY);
|
||||
@ -142,14 +142,14 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
|
||||
}
|
||||
|
||||
int s_len = strlen(sub);
|
||||
const char *str;
|
||||
int n_matches = 0;
|
||||
char matches[n_items][MAX_STR_SIZE];
|
||||
int i = 0;
|
||||
|
||||
/* put all list matches in matches array */
|
||||
for (i = 0; i < n_items; ++i) {
|
||||
str = &L[i * size];
|
||||
char str[MAX_CMDNAME_SIZE + 1];
|
||||
snprintf(str, sizeof(str), "%s", &L[i * size]);
|
||||
|
||||
if (strncasecmp(str, sub, s_len) == 0)
|
||||
strcpy(matches[n_matches++], str);
|
||||
@ -165,10 +165,11 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
|
||||
|
||||
char match[MAX_STR_SIZE];
|
||||
get_str_match(self, match, matches, n_matches);
|
||||
size_t match_len = strlen(match);
|
||||
|
||||
if (dir_search) {
|
||||
if (n_matches == 1)
|
||||
endchrs = char_rfind(match, '.', strlen(match)) ? "\"" : "/";
|
||||
endchrs = char_rfind(match, '.', match_len) ? "\"" : "/";
|
||||
else
|
||||
endchrs = "";
|
||||
} else if (n_matches > 1) {
|
||||
@ -177,18 +178,21 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
|
||||
|
||||
/* put match in correct spot in buf and append endchars */
|
||||
int n_endchrs = strlen(endchrs);
|
||||
int m_len = strlen(match);
|
||||
int strt = ctx->pos - s_len;
|
||||
int diff = m_len - s_len + n_endchrs;
|
||||
int diff = match_len - s_len + n_endchrs;
|
||||
|
||||
if (ctx->len + diff >= MAX_STR_SIZE)
|
||||
return -1;
|
||||
|
||||
char tmpend[MAX_STR_SIZE];
|
||||
snprintf(tmpend, sizeof(tmpend), "%s", &ubuf[ctx->pos]);
|
||||
|
||||
if (match_len + n_endchrs + strlen(tmpend) >= sizeof(ubuf))
|
||||
return -1;
|
||||
|
||||
strcpy(&ubuf[strt], match);
|
||||
strcpy(&ubuf[strt + m_len], endchrs);
|
||||
strcpy(&ubuf[strt + m_len + n_endchrs], tmpend);
|
||||
strcpy(&ubuf[strt + match_len], endchrs);
|
||||
strcpy(&ubuf[strt + match_len + n_endchrs], tmpend);
|
||||
|
||||
/* convert to widechar and copy back to original buf */
|
||||
wchar_t newbuf[MAX_STR_SIZE];
|
||||
|
13
src/chat.c
13
src/chat.c
@ -795,6 +795,10 @@ static void init_infobox(ToxWindow *self)
|
||||
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
(void) y2;
|
||||
|
||||
memset(&ctx->infobox, 0, sizeof(struct infobox));
|
||||
@ -901,7 +905,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (x2 <= 0)
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
if (self->help->active) {
|
||||
@ -999,6 +1003,9 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
@ -1123,6 +1130,10 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
curs_set(1);
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
exit_toxic_err("failed in chat_onInit", FATALERR_CURSES);
|
||||
|
||||
self->x = x2;
|
||||
|
||||
/* Init statusbar info */
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "toxic.h"
|
||||
#include "configdir.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
/* get the user's home directory */
|
||||
void get_home_dir(char *home, int size)
|
||||
@ -69,8 +70,8 @@ char *get_user_config_dir(void)
|
||||
char home[NSS_BUFLEN_PASSWD] = {0};
|
||||
get_home_dir(home, sizeof(home));
|
||||
|
||||
char *user_config_dir;
|
||||
size_t len;
|
||||
char *user_config_dir = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
# if defined(__APPLE__)
|
||||
len = strlen(home) + strlen("/Library/Application Support") + 1;
|
||||
@ -82,9 +83,9 @@ char *get_user_config_dir(void)
|
||||
snprintf(user_config_dir, len, "%s/Library/Application Support", home);
|
||||
# else /* __APPLE__ */
|
||||
|
||||
const char *tmp;
|
||||
const char *tmp = getenv("XDG_CONFIG_HOME");
|
||||
|
||||
if (!(tmp = getenv("XDG_CONFIG_HOME"))) {
|
||||
if (tmp == NULL) {
|
||||
len = strlen(home) + strlen("/.config") + 1;
|
||||
user_config_dir = malloc(len);
|
||||
|
||||
@ -98,6 +99,11 @@ char *get_user_config_dir(void)
|
||||
|
||||
# endif /* __APPLE__ */
|
||||
|
||||
if (!file_exists(user_config_dir)) {
|
||||
free(user_config_dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return user_config_dir;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ int load_blocklist(char *path)
|
||||
memcpy(&tmp, data + i * sizeof(BlockedFriend), sizeof(BlockedFriend));
|
||||
Blocked.list[i].active = true;
|
||||
Blocked.list[i].num = i;
|
||||
Blocked.list[i].namelength = ntohs(tmp.namelength);
|
||||
Blocked.list[i].namelength = MIN(TOXIC_MAX_NAME_LENGTH, ntohs(tmp.namelength));
|
||||
memcpy(Blocked.list[i].name, tmp.name, Blocked.list[i].namelength + 1);
|
||||
memcpy(Blocked.list[i].pub_key, tmp.pub_key, TOX_PUBLIC_KEY_SIZE);
|
||||
|
||||
|
@ -210,6 +210,9 @@ void redraw_groupchat_win(ToxWindow *self)
|
||||
getmaxyx(stdscr, y2, x2);
|
||||
y2 -= 2;
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
if (ctx->sidebar) {
|
||||
delwin(ctx->sidebar);
|
||||
ctx->sidebar = NULL;
|
||||
@ -559,7 +562,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (x2 <= 0)
|
||||
if (x2 <= 0 || y2 <= 0)
|
||||
return;
|
||||
|
||||
if (self->help->active) {
|
||||
@ -649,6 +652,9 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (x2 <= 0 || y2 <= 0)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
@ -713,6 +719,9 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (x2 <= 0 || y2 <= 0)
|
||||
exit_toxic_err("failed in groupchat_onInit", FATALERR_CURSES);
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
||||
|
@ -60,6 +60,9 @@ static void help_init_window(ToxWindow *self, int height, int width)
|
||||
int y2, x2;
|
||||
getmaxyx(stdscr, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
height = MIN(height, y2);
|
||||
width = MIN(width, x2);
|
||||
|
||||
|
@ -202,12 +202,12 @@ size_t write_lookup_data(void *data, size_t size, size_t nmemb, void *user_point
|
||||
struct Recv_Data *recv_data = (struct Recv_Data *) user_pointer;
|
||||
size_t real_size = size * nmemb;
|
||||
|
||||
if (real_size > MAX_RECV_LOOKUP_DATA_SIZE)
|
||||
if (real_size >= MAX_RECV_LOOKUP_DATA_SIZE)
|
||||
return 0;
|
||||
|
||||
memcpy(&recv_data->data, data, real_size);
|
||||
recv_data->size = real_size;
|
||||
recv_data->data[real_size] = 0;
|
||||
recv_data->data[real_size] = '\0';
|
||||
|
||||
return real_size;
|
||||
}
|
||||
|
12
src/prompt.c
12
src/prompt.c
@ -185,7 +185,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (x2 <= 0)
|
||||
if (x2 <= 0 || y2 <= 0)
|
||||
return;
|
||||
|
||||
/* ignore non-menu related input if active */
|
||||
@ -256,6 +256,9 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
@ -431,6 +434,10 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
||||
{
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
exit_toxic_err("failed in prompt_init_statusbar", FATALERR_CURSES);
|
||||
|
||||
(void) y2;
|
||||
|
||||
/* Init statusbar info */
|
||||
@ -488,6 +495,9 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
|
||||
int y2, x2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
exit_toxic_err("failed in prompt_onInit", FATALERR_CURSES);
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
|
||||
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
||||
|
@ -88,6 +88,7 @@ typedef enum _FATAL_ERRS {
|
||||
FATALERR_PROXY = -10, /* Tox network failed to init using a proxy */
|
||||
FATALERR_ENCRYPT = -11, /* Data file encryption failure */
|
||||
FATALERR_TOX_INIT = -12, /* Tox instance failed to initialize */
|
||||
FATALERR_CURSES = -13, /* Unrecoverable Ncurses error */
|
||||
} FATAL_ERRS;
|
||||
|
||||
/* Fixes text color problem on some terminals.
|
||||
|
@ -153,9 +153,10 @@ int stop_video_transmission(Call *call, int friend_number)
|
||||
CallControl.video_bit_rate = 0;
|
||||
toxav_bit_rate_set(CallControl.av, friend_number, -1, CallControl.video_bit_rate, NULL);
|
||||
|
||||
if ( call->vin_idx != -1 )
|
||||
if ( call->vin_idx != -1 ) {
|
||||
close_video_device(vdt_input, call->vin_idx);
|
||||
call->vin_idx = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -190,12 +191,12 @@ void callback_recv_video_starting(uint32_t friend_number)
|
||||
{
|
||||
return;
|
||||
|
||||
Call* this_call = &CallControl.calls[friend_number];
|
||||
// Call* this_call = &CallControl.calls[friend_number];
|
||||
|
||||
if ( this_call->vout_idx != -1 )
|
||||
return;
|
||||
// if ( this_call->vout_idx != -1 )
|
||||
// return;
|
||||
|
||||
open_primary_video_device(vdt_output, &this_call->vout_idx);
|
||||
// open_primary_video_device(vdt_output, &this_call->vout_idx);
|
||||
}
|
||||
void callback_recv_video_end(uint32_t friend_number)
|
||||
{
|
||||
@ -243,37 +244,37 @@ void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
|
||||
{
|
||||
return; // TODO: Fix video
|
||||
|
||||
const char *error_str;
|
||||
Call* this_call = &CallControl.calls[self->num];
|
||||
// const char *error_str;
|
||||
// Call* this_call = &CallControl.calls[self->num];
|
||||
|
||||
if ( argc != 0 ) {
|
||||
error_str = "Unknown arguments.";
|
||||
goto on_error;
|
||||
}
|
||||
// if ( argc != 0 ) {
|
||||
// error_str = "Unknown arguments.";
|
||||
// goto on_error;
|
||||
// }
|
||||
|
||||
if ( !CallControl.av ) {
|
||||
error_str = "ToxAV not supported!";
|
||||
goto on_error;
|
||||
}
|
||||
// if ( !CallControl.av ) {
|
||||
// error_str = "ToxAV not supported!";
|
||||
// goto on_error;
|
||||
// }
|
||||
|
||||
if ( !self->stb->connection ) {
|
||||
error_str = "Friend is offline.";
|
||||
goto on_error;
|
||||
}
|
||||
// if ( !self->stb->connection ) {
|
||||
// error_str = "Friend is offline.";
|
||||
// goto on_error;
|
||||
// }
|
||||
|
||||
if ( !self->is_call ) {
|
||||
error_str = "Not in call!";
|
||||
goto on_error;
|
||||
}
|
||||
// if ( !self->is_call ) {
|
||||
// error_str = "Not in call!";
|
||||
// goto on_error;
|
||||
// }
|
||||
|
||||
if ( this_call->vin_idx == -1 )
|
||||
callback_video_starting(self->num);
|
||||
else
|
||||
callback_video_end(self->num);
|
||||
// if ( this_call->vin_idx == -1 )
|
||||
// callback_video_starting(self->num);
|
||||
// else
|
||||
// callback_video_end(self->num);
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
// return;
|
||||
// on_error:
|
||||
// print_err (self, error_str);
|
||||
}
|
||||
|
||||
void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
|
@ -400,6 +400,9 @@ void on_window_resize(void)
|
||||
getmaxyx(stdscr, y2, x2);
|
||||
y2 -= 2;
|
||||
|
||||
if (y2 <= 0 || x2 <= 0)
|
||||
return;
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
|
Loading…
Reference in New Issue
Block a user