Re: [PATCH] set initial length of string to 0 instead of 64

From: David Laight

Date: Wed Oct 22 2025 - 05:05:31 EST


On Tue, 21 Oct 2025 22:51:59 +0530
Biancaa Ramesh <biancaa2210329@xxxxxxxxxx> wrote:

Nak

> Signed-off-by: Biancaa Ramesh <biancaa2210329@xxxxxxxxxx>
> ---
> scripts/kconfig/util.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
> index 176ec03bb3f0..f55e3ce496e1 100644
> --- a/scripts/kconfig/util.c
> +++ b/scripts/kconfig/util.c
> @@ -64,13 +64,14 @@ const char *file_lookup(const char *name)
> struct gstr str_new(void)
> {
> struct gstr gs;
> - gs.s = xmalloc(sizeof(char) * 64);
> - gs.len = 64;
> + gs.s = xmalloc(64); // allocate buffer

That is 'no-change'.

> + gs.len = 0; // string is empty

I'm pretty sure gs.len is the size of the buffer, so should be 64.

> gs.max_width = 0;
> - strscpy(gs.s, "\0");

Where did that strscpy() come from, it is wrong and shouldn't compile.

> + gs.s[0] = '\0'; // initialize as empty string

Equivalent to the strcpy() in 6.18-rc2.

> return gs;
> }
>
> +
> /* Free storage for growable string */
> void str_free(struct gstr *gs)
> {