Fix strlcpy(3) and strlcat(3) being horribly broken.

Found by musl's libc-test.

This is just embarrassing.
This commit is contained in:
Jonas 'Sortie' Termansen 2014-08-03 00:00:14 +02:00
parent 395f7b29b4
commit b0cbf9d0ea
2 changed files with 4 additions and 5 deletions

View File

@ -29,7 +29,6 @@ size_t strlcat(char* restrict dest, const char* restrict src, size_t size)
{ {
size_t dest_len = strnlen(dest, size); size_t dest_len = strnlen(dest, size);
if ( size <= dest_len ) if ( size <= dest_len )
return dest_len; return dest_len + strlen(src);
strcpy(dest + strlen(dest), src);
return dest_len + strlcpy(dest + dest_len, src, size - dest_len); return dest_len + strlcpy(dest + dest_len, src, size - dest_len);
} }

View File

@ -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. 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) size_t strlcpy(char* restrict dest, const char* restrict src, size_t size)
{ {
if ( !size ) if ( !size )
return 0; return strlen(src);
size_t result; size_t result;
for ( result = 0; result < size-1 && src[result]; result++ ) for ( result = 0; result < size-1 && src[result]; result++ )
dest[result] = src[result]; dest[result] = src[result];
dest[result] = '\0'; dest[result] = '\0';
return result; return result + strlen(src + result);
} }