Re: [PATCH] tools: include: add proper strscpy() declaration

From: Wei Yang

Date: Wed May 06 2026 - 22:42:19 EST


On Wed, May 06, 2026 at 06:34:52PM +0200, Lucas Poupeau wrote:
>Remove the macro hack and add a proper implementation in tools/lib/string.c.
>This avoids unsafe strcpy usage when strscpy is expected and fixes
>potential compilation warnings regarding str_error_r.
>
>Fixes: 9e3d665 ("memblock test: fix implicit declaration of function 'strscpy'")

The Fixes tag seems not necessary.

>Suggested-by: Maxwell Doose <m32285159@xxxxxxxxx>
>Reviewed-by: Wei Yang <richard.weiyang@xxxxxxxxx>

Hmm... I didn't see your change before, so I can't reviewed yet.

It is not proper to add RB by yourself.

>Signed-off-by: Lucas Poupeau <lucasp.linux@xxxxxxxxx>
>---
> tools/include/linux/string.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
>index 51ad3cf4fa82..d6e53109e786 100644
>--- a/tools/include/linux/string.h
>+++ b/tools/include/linux/string.h
>@@ -12,7 +12,7 @@ void argv_free(char **argv);
>
> int strtobool(const char *s, bool *res);
>
>-#define strscpy strcpy
>+ssize_t strscpy(char *dest, const char *src, size_t count);
>

You mean add proper implementation, but this is just a declaration.
Where is the definition in tools/lib/string.c? Something is missed?

After applying your patch, I got this when build tools/testing/memblock.


memblock.c: In function ‘reserved_mem_add’:
memblock.c:2464:9: error: too few arguments to function ‘strscpy’
2464 | strscpy(map->name, name);
| ^~~~~~~
In file included from ./linux/kernel.h:11,
from memblock.c:9:
../../include/linux/string.h:16:9: note: declared here
16 | ssize_t strscpy(char *dest, const char *src, size_t count);
| ^~~~~~~
make: *** [<builtin>: memblock.o] Error 1

> /*
> * glibc based builds needs the extern while uClibc doesn't.
>--
>2.54.0

--
Wei Yang
Help you, Help me