Commit fbffce81 authored by Rodrigo Campos's avatar Rodrigo Campos Committed by Thomas Weißschuh

tools/nolibc: Fix strlcpy() return code and size usage

The return code should always be strlen(src), and we should copy at most
size-1 bytes.

While we are there, make sure to null-terminate the dst buffer if we
copied something.
Signed-off-by: default avatarRodrigo Campos <rodrigo@sdfg.com.ar>
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
parent 34d232c3
...@@ -219,16 +219,18 @@ static __attribute__((unused)) ...@@ -219,16 +219,18 @@ static __attribute__((unused))
size_t strlcpy(char *dst, const char *src, size_t size) size_t strlcpy(char *dst, const char *src, size_t size)
{ {
size_t len; size_t len;
char c;
for (len = 0;;) { for (len = 0; len < size; len++) {
c = src[len]; dst[len] = src[len];
if (len < size) if (!dst[len])
dst[len] = c; return len;
if (!c)
break;
len++;
} }
if (size)
dst[size-1] = '\0';
while (src[len])
len++;
return len; return len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment