From: Masahiro Yamada Date: Fri, 2 Feb 2024 15:58:15 +0000 (+0900) Subject: kconfig: make file::name a flexible array member X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6676c5bc15e66268c9c9669d5852aa779689c74e;p=people%2Faperard%2Flinux.git kconfig: make file::name a flexible array member Call malloc() just once to allocate needed memory. Signed-off-by: Masahiro Yamada --- diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 85e0d1ab3c8ad..760b1e681b433 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,7 +19,7 @@ extern "C" { struct file { struct file *next; - const char *name; + char name[]; }; typedef enum tristate { diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 958543bb0a37a..2636dccea0c9a 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -13,6 +13,7 @@ struct file *file_lookup(const char *name) { struct file *file; + size_t len; for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { @@ -20,9 +21,11 @@ struct file *file_lookup(const char *name) } } - file = xmalloc(sizeof(*file)); + len = strlen(name); + file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); - file->name = xstrdup(name); + memcpy(file->name, name, len); + file->name[len] = '\0'; file->next = file_list; file_list = file;