mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-27 02:13:28 +01:00
handle errors for name functions
This commit is contained in:
parent
4238c20e72
commit
141b36af04
@ -288,11 +288,9 @@ static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum,
|
|||||||
char timefrmt[TIME_STR_SIZE];
|
char timefrmt[TIME_STR_SIZE];
|
||||||
get_time_str(timefrmt, sizeof(timefrmt));
|
get_time_str(timefrmt, sizeof(timefrmt));
|
||||||
|
|
||||||
/* announce title when we join the room */
|
/* don't announce title when we join the room */
|
||||||
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT)) {
|
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT))
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
char nick[TOX_MAX_NAME_LENGTH];
|
char nick[TOX_MAX_NAME_LENGTH];
|
||||||
get_group_nick_truncate(m, nick, peernum, groupnum);
|
get_group_nick_truncate(m, nick, peernum, groupnum);
|
||||||
|
@ -261,10 +261,17 @@ void str_to_lower(char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
|
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
|
||||||
Returns nick len on success, -1 on failure */
|
if toxcore API call fails, put UNKNOWN_NAME in buf
|
||||||
|
Returns nick len */
|
||||||
int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
||||||
{
|
{
|
||||||
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
|
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
|
||||||
|
|
||||||
|
if (len == -1) {
|
||||||
|
strcpy(buf, UNKNOWN_NAME);
|
||||||
|
len = strlen(UNKNOWN_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
filter_str(buf, len);
|
filter_str(buf, len);
|
||||||
@ -275,6 +282,12 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
|||||||
int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum)
|
int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum)
|
||||||
{
|
{
|
||||||
int len = tox_group_peername(m, groupnum, peernum, (uint8_t *) buf);
|
int len = tox_group_peername(m, groupnum, peernum, (uint8_t *) buf);
|
||||||
|
|
||||||
|
if (len == -1) {
|
||||||
|
strcpy(buf, UNKNOWN_NAME);
|
||||||
|
len = strlen(UNKNOWN_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
filter_str(buf, len);
|
filter_str(buf, len);
|
||||||
|
Loading…
Reference in New Issue
Block a user