Re: [PATCH] tools: include: add proper strscpy() declaration
From: Maxwell Doose
Date: Wed May 06 2026 - 23:11:45 EST
On Wed, May 6, 2026 at 9:42 PM Wei Yang <richard.weiyang@xxxxxxxxx> wrote:
>
> 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.
>
Perhaps...let's get rid of that.
>
> >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.
No clue how this got added. Lucas, please remove this tag, as Wei
didn't give an RB.
>
> >Signed-off-by: Lucas Poupeau <lucasp.linux@xxxxxxxxx>
>
Lucas, make sure you add the changes Wei asked for as well.
>
> >---
> > 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
>
Ah...seems like a signature mismatch. Too bad testing/memblock is
reliant on this crap macro now... Lucas, make sure when you're testing
this that you build the ENTIRE kernel, since there may be hidden
dependencies like this.
best regards,
max
> > /*
> > * glibc based builds needs the extern while uClibc doesn't.
> >--
> >2.54.0
>
> --
> Wei Yang
> Help you, Help me