From: Nick Bowler Date: Sun, 27 Feb 2022 05:18:04 +0000 (-0500) Subject: uobject: Simplify lookup_module function. X-Git-Url: http://git.draconx.ca/gitweb/upkg.git/commitdiff_plain/dc6cf2d7ff5aea68888bf648be23754ffe5b18ba uobject: Simplify lookup_module function. We don't need this function to double as a C compiler test case. Not doing weird things with flexible array members seems to be much simpler. --- diff --git a/src/uobject/module.c b/src/uobject/module.c index ff6bd5a..1d41d07 100644 --- a/src/uobject/module.c +++ b/src/uobject/module.c @@ -80,19 +80,16 @@ int u_object_module_exit(void) static int lookup_module(GTypeModule **out, const char *name) { - struct { GTypeModule pkg; char buf[]; } *search_key; - GTypeModule *result; + GTypeModule *result, key = {0}; + char *buf; - search_key = malloc(sizeof *search_key + strlen(name) + 1); - if (!search_key) + buf = malloc(strlen(name) + 1); + if (!buf) return -1; - search_key->pkg = (GTypeModule) { - .name = str_cpy_lower(search_key->buf, name), - }; - - result = avl_find(package_tree, search_key); - free(search_key); + key.name = str_cpy_lower(buf, name); + result = avl_find(package_tree, &key); + free(buf); *out = result; return 0;