mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-19 19:14:55 +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;
|
size_t len;
|
||||||
|
|
||||||
for (len = 0; *dst && size > 1; ++len, --size)
|
for (len = 0; *dst && len < size; ++len, ++dst)
|
||||||
dst++;
|
/* nothing */;
|
||||||
for (; *src && size > 1; ++len, --size)
|
for (; *src && len + 1 < size; ++len, ++src, ++dst)
|
||||||
*dst++ = *src++;
|
*dst = *src;
|
||||||
*dst = '\0';
|
if (len < size)
|
||||||
|
*dst = '\0';
|
||||||
while (*src)
|
while (*src)
|
||||||
++len, ++src;
|
++len, ++src;
|
||||||
return (len);
|
return (len);
|
||||||
|
|
Loading…
Reference in a new issue