Commit 6676c5bc authored by Masahiro Yamada's avatar Masahiro Yamada

kconfig: make file::name a flexible array member

Call malloc() just once to allocate needed memory.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 8facc5f3
......@@ -19,7 +19,7 @@ extern "C" {
struct file {
struct file *next;
const char *name;
char name[];
};
typedef enum tristate {
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment