1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 20:07:46 +02:00

adjusting max name length handling

This commit is contained in:
Jfreegman 2013-10-18 23:08:37 -04:00
parent fe0ccf52e9
commit 361c4cfafc
3 changed files with 9 additions and 20 deletions

View File

@ -27,6 +27,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_getname(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
print_time(ctx->history);
wattron(ctx->history, COLOR_PAIR(4));
@ -62,6 +63,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_getname(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
print_time(ctx->history);
wattron(ctx->history, COLOR_PAIR(YELLOW));
@ -77,6 +79,8 @@ static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t
if (self->num != num)
return;
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
len = strlen(nick) + 1;
memcpy(self->name, nick, len);
}
@ -245,9 +249,6 @@ static void chat_sendfile(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *pa
fseek(file_to_send, 0, SEEK_SET);
int friendnum = self->num;
uint8_t friendname[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_getname(m, friendnum, friendname);
int filenum = tox_new_filesender(m, friendnum, filesize, path, path_len + 1);
if (filenum == -1) {

View File

@ -42,6 +42,8 @@ static void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint
if (len >= TOX_MAX_NAME_LENGTH || num < 0 || num >= num_friends)
return;
str[TOXIC_MAX_NAME_LENGTH] = '\0';
len = strlen(str) + 1;
memcpy(friends[num].name, str, len);
friends[num].namelength = len;
}
@ -82,6 +84,9 @@ int friendlist_onFriendAdded(Tox *m, int num)
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
strcpy((char *) friends[i].name, UNKNOWN_NAME);
friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
} else { /* Enforce toxic's maximum name length */
friends[i].name[TOXIC_MAX_NAME_LENGTH] = '\0';
friends[i].namelength = strlen(friends[i].name) + 1;
}
if (i == num_friends)

View File

@ -62,23 +62,6 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v
if (friendnumber < 0 || friendnumber > MAX_FRIENDS_NUM)
return;
if (length >= TOXIC_MAX_NAME_LENGTH) { /* length includes null byte */
string[TOXIC_MAX_NAME_LENGTH] = L'\0';
length = TOXIC_MAX_NAME_LENGTH + 1;
tox_setfriendname(m, friendnumber, string, length);
}
/* Append friendnumber to duplicate nicks to guarantee uniqueness */
int n = get_friendnum(string);
if (n != friendnumber && n != -1) {
char n_buf[strlen(string)+4]; /* must have room for friendnum chars relative to MAX_FRIENDS_NUM */
snprintf(n_buf, sizeof(n_buf), "%s%d", string, friendnumber);
strcpy(string, n_buf);
length = strlen(n_buf) + 1;
tox_setfriendname(m, friendnumber, string, length);
}
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {