1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 14:47:46 +02:00

Fix formatting bug caused by strings containing \r

This commit is contained in:
jfreegman 2017-08-28 18:26:52 -04:00
parent ab490d28b4
commit 80c0500299
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -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.