mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:33:02 +01:00
Fix formatting bug caused by strings containing \r
This commit is contained in:
parent
ab490d28b4
commit
80c0500299
@ -372,14 +372,22 @@ on_error:
|
||||
return len;
|
||||
}
|
||||
|
||||
/* copies data to msg buffer.
|
||||
/* copies data to msg buffer, removing return characters.
|
||||
returns length of msg, which will be no larger than size-1 */
|
||||
size_t copy_tox_str(char *msg, size_t size, const char *data, size_t length)
|
||||
{
|
||||
size_t len = MIN(length, size - 1);
|
||||
memcpy(msg, data, len);
|
||||
msg[len] = '\0';
|
||||
return len;
|
||||
size_t i;
|
||||
size_t j = 0;
|
||||
|
||||
for (i = 0; (i < length) && (j < size - 1); ++i) {
|
||||
if (data[i] != '\r') {
|
||||
msg[j++] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
msg[j] = '\0';
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
/* returns index of the first instance of ch in s starting at idx.
|
||||
|
Loading…
Reference in New Issue
Block a user