From: Lucas De Marchi Date: Tue, 13 Dec 2011 15:07:40 +0000 (-0200) Subject: kmod_module: use pointer instead of vector for its name X-Git-Tag: v1~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=219f9c38bb283f6173ed37d1eb54671e1ca52349;p=thirdparty%2Fkmod.git kmod_module: use pointer instead of vector for its name We still have name allocated just after the struct kmod_module, but now we use a pointer instead of putting name as a vector in the end of the structure. The previous way has some problems, the worst is: - it's not possible to swap the name with another value: this is the real problem that this patch is solving. Later patches will make name be swappable with alias, which is not possible if name is a vector. --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 9429f1d7..0e71aea7 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -45,6 +45,7 @@ */ struct kmod_module { struct kmod_ctx *ctx; + char *name; char *path; struct kmod_list *dep; char *options; @@ -58,7 +59,6 @@ struct kmod_module { bool install_commands : 1; bool remove_commands : 1; } init; - char name[]; }; inline char *modname_normalize(const char *modname, char buf[NAME_MAX], @@ -214,6 +214,7 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, } m->ctx = kmod_ref(ctx); + m->name = (char *)m + sizeof(*m); memcpy(m->name, name_norm, namelen + 1); m->refcount = 1; @@ -275,6 +276,7 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, return -errno; m->ctx = kmod_ref(ctx); + m->name = (char *)m + sizeof(*m); memcpy(m->name, name, namelen); m->path = abspath; m->refcount = 1;