summaryrefslogtreecommitdiff
path: root/scripts/kconfig/util.c
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2024-02-03 00:58:15 +0900
committerMasahiro Yamada <masahiroy@kernel.org>2024-02-19 18:20:41 +0900
commit6676c5bc15e66268c9c9669d5852aa779689c74e (patch)
tree94c53ce02df799a82ec7b76cfa4cb5315f4fd49f /scripts/kconfig/util.c
parent8facc5f31954d5fddc2759de474eb6fae1135ced (diff)
kconfig: make file::name a flexible array member
Call malloc() just once to allocate needed memory. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts/kconfig/util.c')
-rw-r--r--scripts/kconfig/util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index 958543bb0a37..2636dccea0c9 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;