diff --git a/src/commands.c b/src/commands.c index ae7c647..56b2d3a 100644 --- a/src/commands.c +++ b/src/commands.c @@ -50,7 +50,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv on_friendadded(m, friendnum); } - memset(&pending_frnd_requests[num], 0, sizeof(TOX_CLIENT_ID_SIZE)); + memset(&pending_frnd_requests[num], 0, TOX_CLIENT_ID_SIZE); int i; diff --git a/src/misc_tools.c b/src/misc_tools.c index e4f6a88..2c5ac7b 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -59,17 +59,17 @@ int string_is_empty(char *string) /* convert wide characters to null terminated string */ uint8_t *wcs_to_char(wchar_t *string) { - size_t len = 0; uint8_t *ret = NULL; + size_t len = wcstombs(NULL, string, 0); - len = wcstombs(NULL, string, 0); if (len != (size_t) -1) { - len++; - ret = malloc(len); + ret = malloc(len+1); + if (ret != NULL) wcstombs(ret, string, len); } else { ret = malloc(2); + if (ret != NULL) { ret[0] = ' '; ret[1] = '\0'; @@ -88,10 +88,9 @@ uint8_t *wcs_to_char(wchar_t *string) /* convert a wide char to null terminated string */ char *wc_to_char(wchar_t ch) { - int len = 0; static char ret[MB_LEN_MAX + 1]; + int len = wctomb(ret, ch); - len = wctomb(ret, ch); if (len == -1) { ret[0] = ' '; ret[1] = '\0'; diff --git a/src/prompt.c b/src/prompt.c index 4a772dd..7b859da 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -136,7 +136,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key) /* Add printable characters to line */ else if (isprint(key)) { - if (prompt_buf_pos < (MAX_STR_SIZE-1)) { + if (prompt_buf_pos <= MAX_STR_SIZE) { mvwaddch(self->window, y, x, key); prompt_buf[prompt_buf_pos++] = key; prompt_buf[prompt_buf_pos] = '\0';