mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
kconfig: make file::name a flexible array member
Call malloc() just once to allocate needed memory. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
parent
8facc5f319
commit
6676c5bc15
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user