diff --git a/src/chat.c b/src/chat.c index 0d34c6e..9111423 100644 --- a/src/chat.c +++ b/src/chat.c @@ -126,7 +126,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *msg, u uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; @@ -175,7 +175,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, uint8_t *action, uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);; + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1);; nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; @@ -191,7 +191,7 @@ static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_t *nic if (self->num != num) return; - len = MIN(len, TOXIC_MAX_NAME_LENGTH); + len = MIN(len, TOXIC_MAX_NAME_LENGTH-1); nick[len] = '\0'; strcpy(self->name, nick); } @@ -352,7 +352,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, ui uint8_t msg[MAX_STR_SIZE + TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, friendnumber, name); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); name[n_len] = '\0'; snprintf(msg, sizeof(msg), "%s has invited you to a group chat.\n" @@ -916,7 +916,7 @@ ToxWindow new_chat(Tox *m, int32_t friendnum) uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'}; int len = tox_get_name(m, friendnum, name); - len = MIN(len, TOXIC_MAX_NAME_LENGTH); + len = MIN(len, TOXIC_MAX_NAME_LENGTH-1); name[len] = '\0'; strcpy(ret.name, name); diff --git a/src/friendlist.c b/src/friendlist.c index 8f8b8e4..ecb9054 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -106,7 +106,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t * uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; int n_len = tox_get_name(m, num, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; @@ -137,7 +137,7 @@ static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_ if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index) return; - len = MIN(len, TOXIC_MAX_NAME_LENGTH); + len = MIN(len, TOXIC_MAX_NAME_LENGTH-1); str[len] = '\0'; strcpy(friends[num].name, str); @@ -216,7 +216,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; @@ -239,7 +239,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8 } else { uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; @@ -547,7 +547,7 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av) uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; int n_len = tox_get_name(m, id, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; diff --git a/src/global_commands.c b/src/global_commands.c index f2ff684..deb1b93 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -335,8 +335,7 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA return; } - if (len >= TOXIC_MAX_NAME_LENGTH) - len = TOXIC_MAX_NAME_LENGTH; + len = MIN(len, TOXIC_MAX_NAME_LENGTH-1); nick[len] = L'\0'; diff --git a/src/groupchat.c b/src/groupchat.c index 57c3ed2..471a634 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -164,7 +164,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; int n_len = tox_group_peername(m, groupnum, peernum, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); /* enforce client max name length */ + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); /* enforce client max name length */ nick[n_len] = '\0'; /* check if message contains own name and alert appropriately */ @@ -224,7 +224,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; n_len = tox_group_peername(m, groupnum, peernum, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; @@ -268,7 +268,7 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui memcpy(&groupchats[gnum].peer_names[i*N], peerlist[i], N); uint16_t n_len = lengths[i]; - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); groupchats[gnum].peer_names[i*N+n_len] = '\0'; groupchats[gnum].peer_name_lengths[i] = n_len; diff --git a/src/prompt.c b/src/prompt.c index a61cc80..f5d4706 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -371,7 +371,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, friendnum, nick); - n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); + n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH-1); if (!nick[0]) { snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);