mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-18 18:44:53 +00:00
Fix a bug that affected unterminated buffers: strlcat() would write a NUL
past the end of the buffer and return one less than the correct length.
This commit is contained in:
parent
08208a1b3e
commit
3ed82792fc
1 changed files with 6 additions and 5 deletions
|
@ -43,11 +43,12 @@ cryb_strlcat(char *dst, const char *src, size_t size)
|
|||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; *dst && size > 1; ++len, --size)
|
||||
dst++;
|
||||
for (; *src && size > 1; ++len, --size)
|
||||
*dst++ = *src++;
|
||||
*dst = '\0';
|
||||
for (len = 0; *dst && len < size; ++len, ++dst)
|
||||
/* nothing */;
|
||||
for (; *src && len + 1 < size; ++len, ++src, ++dst)
|
||||
*dst = *src;
|
||||
if (len < size)
|
||||
*dst = '\0';
|
||||
while (*src)
|
||||
++len, ++src;
|
||||
return (len);
|
||||
|
|
Loading…
Reference in a new issue