mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-05 20:26:46 +02:00
safer string handling
This commit is contained in:
@ -250,11 +250,21 @@ void str_to_lower(char *str)
|
||||
int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
||||
{
|
||||
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH);
|
||||
buf[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
|
||||
/* copies data to msg buffer.
|
||||
returns length of msg, which will be no larger than size-1 */
|
||||
uint16_t copy_tox_str(char *msg, size_t size, const char *data, uint16_t length)
|
||||
{
|
||||
int len = MIN(length, size - 1);
|
||||
memcpy(msg, data, len);
|
||||
msg[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
|
||||
/* returns index of the first instance of ch in s starting at idx.
|
||||
returns length of s if char not found */
|
||||
int char_find(int idx, const char *s, char ch)
|
||||
|
Reference in New Issue
Block a user