diff --git a/src/autocomplete.c b/src/autocomplete.c index 45eb321..b074771 100644 --- a/src/autocomplete.c +++ b/src/autocomplete.c @@ -279,7 +279,7 @@ static void complete_home_dir(ToxWindow *self, char *path, int pathsize, const c char homedir[MAX_STR_SIZE] = {0}; get_home_dir(homedir, sizeof(homedir)); - char newline[MAX_STR_SIZE]; + char newline[MAX_STR_SIZE + 1]; snprintf(newline, sizeof(newline), "%s %s%s", cmd, homedir, path + 1); snprintf(path, pathsize, "%s", &newline[cmdlen - 1]); @@ -309,12 +309,12 @@ static void complete_home_dir(ToxWindow *self, char *path, int pathsize, const c #define MAX_DIRS 512 int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd) { - char b_path[MAX_STR_SIZE]; - char b_name[MAX_STR_SIZE]; + char b_path[MAX_STR_SIZE + 1]; + char b_name[MAX_STR_SIZE + 1]; char b_cmd[MAX_STR_SIZE]; const wchar_t *tmpline = &line[wcslen(cmd) + 1]; /* start after "/command " */ - if (wcs_to_mbs_buf(b_path, tmpline, sizeof(b_path)) == -1) { + if (wcs_to_mbs_buf(b_path, tmpline, sizeof(b_path) - 1) == -1) { return -1; } @@ -323,7 +323,7 @@ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd) } if (b_path[0] == '~') { - complete_home_dir(self, b_path, sizeof(b_path), b_cmd, strlen(b_cmd) + 2); + complete_home_dir(self, b_path, sizeof(b_path) - 1, b_cmd, strlen(b_cmd) + 2); } int si = char_rfind(b_path, '/', strlen(b_path)); @@ -332,9 +332,8 @@ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd) b_path[0] = '.'; b_path[1] = '\0'; } else if (!si && b_path[0] != '/') { /* look for matches in pwd */ - char tmp[MAX_STR_SIZE]; - snprintf(tmp, sizeof(tmp), ".%s", b_path); - snprintf(b_path, sizeof(b_path), "%s", tmp); + memmove(b_path + 1, b_path, sizeof(b_path) - 1); + b_path[0] = '.'; } snprintf(b_name, sizeof(b_name), "%s", &b_path[si + 1]); diff --git a/src/chat.c b/src/chat.c index c254e49..00f1262 100644 --- a/src/chat.c +++ b/src/chat.c @@ -1306,7 +1306,8 @@ static void chat_onInit(ToxWindow *self, Tox *m) char nick[TOX_MAX_NAME_LENGTH + 1]; size_t n_len = get_nick_truncate(m, nick, self->num); - snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick); + memcpy(statusbar->nick, nick, n_len); + statusbar->nick[n_len] = 0; statusbar->nick_len = n_len; /* Init subwindows */ diff --git a/src/friendlist.c b/src/friendlist.c index 77f45ad..709094d 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -491,10 +491,11 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort) update_friend_last_online(i, t); - char tempname[TOX_MAX_NAME_LENGTH] = {0}; - get_nick_truncate(m, tempname, num); - snprintf(Friends.list[i].name, sizeof(Friends.list[i].name), "%s", tempname); - Friends.list[i].namelength = strlen(Friends.list[i].name); + char tempname[TOX_MAX_NAME_LENGTH + 1]; + int name_len = get_nick_truncate(m, tempname, num); + memcpy(Friends.list[i].name, tempname, name_len); + Friends.list[i].name[name_len] = 0; + Friends.list[i].namelength = name_len; if (i == Friends.max_idx) { ++Friends.max_idx; diff --git a/src/group_commands.c b/src/group_commands.c index 56c7fa7..f70a1c3 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -75,7 +75,7 @@ void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg line_info_add(self, timefrmt, selfnick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title); - char tmp_event[MAX_STR_SIZE]; + char tmp_event[MAX_STR_SIZE + 20]; snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title); write_to_log(tmp_event, selfnick, self->chatwin->log, true); } diff --git a/src/name_lookup.c b/src/name_lookup.c index bed5a17..b52f98a 100644 --- a/src/name_lookup.c +++ b/src/name_lookup.c @@ -269,7 +269,7 @@ void *lookup_thread_func(void *data) memset(&recv_data, 0, sizeof(struct Recv_Curl_Data)); - char post_data[MAX_STR_SIZE]; + char post_data[MAX_STR_SIZE + 30]; snprintf(post_data, sizeof(post_data), "{\"action\": 3, \"name\": \"%s\"}", name);