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

handle errors for name functions

This commit is contained in:
Jfreegman
2014-11-15 22:39:24 -05:00
parent 4238c20e72
commit 141b36af04
2 changed files with 16 additions and 5 deletions

View File

@ -261,10 +261,17 @@ void str_to_lower(char *str)
}
/* 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 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);
buf[len] = '\0';
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 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);
buf[len] = '\0';
filter_str(buf, len);