mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix strlcpy(3) and strlcat(3) being horribly broken.
Found by musl's libc-test. This is just embarrassing.
This commit is contained in:
parent
395f7b29b4
commit
b0cbf9d0ea
2 changed files with 4 additions and 5 deletions
|
@ -29,7 +29,6 @@ size_t strlcat(char* restrict dest, const char* restrict src, size_t size)
|
|||
{
|
||||
size_t dest_len = strnlen(dest, size);
|
||||
if ( size <= dest_len )
|
||||
return dest_len;
|
||||
strcpy(dest + strlen(dest), src);
|
||||
return dest_len + strlen(src);
|
||||
return dest_len + strlcpy(dest + dest_len, src, size - dest_len);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -28,10 +28,10 @@ extern "C"
|
|||
size_t strlcpy(char* restrict dest, const char* restrict src, size_t size)
|
||||
{
|
||||
if ( !size )
|
||||
return 0;
|
||||
return strlen(src);
|
||||
size_t result;
|
||||
for ( result = 0; result < size-1 && src[result]; result++ )
|
||||
dest[result] = src[result];
|
||||
dest[result] = '\0';
|
||||
return result;
|
||||
return result + strlen(src + result);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue