mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-20 03:24:54 +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,10 +43,11 @@ 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;
|
||||||
|
if (len < size)
|
||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
while (*src)
|
while (*src)
|
||||||
++len, ++src;
|
++len, ++src;
|
||||||
|
|
Loading…
Reference in a new issue