mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 16:03:27 +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;
|
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 */
|
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 copy_tox_str(char *msg, size_t size, const char *data, size_t length)
|
||||||
{
|
{
|
||||||
size_t len = MIN(length, size - 1);
|
size_t i;
|
||||||
memcpy(msg, data, len);
|
size_t j = 0;
|
||||||
msg[len] = '\0';
|
|
||||||
return len;
|
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.
|
/* returns index of the first instance of ch in s starting at idx.
|
||||||
|
Loading…
Reference in New Issue
Block a user