From 38992d9824feb376f9f80d0c84d14c2d1ffc3268 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 26 Jun 2022 11:58:06 -0700 Subject: [PATCH] gvplugin_load: use a 'strview_t' for 'reqdep' Slightly more readable and less error prone than doing this inline. --- lib/gvc/gvplugin.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 45e3ad5b9..cfe441ffa 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -268,20 +268,14 @@ gvplugin_available_t *gvplugin_load(GVC_t * gvc, api_t api, const char *str) size_t reqtyp_len = reqtyp_end == NULL ? strlen(reqtyp) : (size_t)(reqtyp_end - reqtyp); - const char *reqdep = NULL; - const char *reqdep_end = NULL; - size_t reqdep_len = 0; + strview_t reqdep = {NULL}; strview_t reqpkg = {NULL}; if (reqtyp_end != NULL) { - reqdep = reqtyp_end + strlen(":"); - reqdep_end = strchr(reqdep, ':'); - if (reqdep_end != NULL) { - reqdep_len = (size_t)(reqdep_end - reqdep); - reqpkg = strview(reqdep_end + strlen(":"), '\0'); - } else { - reqdep_len = strlen(reqdep); + reqdep = strview(reqtyp_end + strlen(":"), ':'); + if (reqdep.data[reqdep.size] == ':') { + reqpkg = strview(reqdep.data + reqdep.size + strlen(":"), '\0'); } } @@ -299,8 +293,8 @@ gvplugin_available_t *gvplugin_load(GVC_t * gvc, api_t api, const char *str) if (typ_len != reqtyp_len || strncmp(typ, reqtyp, reqtyp_len)) continue; /* types empty or mismatched */ - if (dep.data && reqdep) { - if (dep.size != reqdep_len || strncmp(dep.data, reqdep, reqdep_len)) { + if (dep.data && reqdep.data) { + if (!strview_eq(dep, reqdep)) { continue; /* dependencies not empty, but mismatched */ } } -- 2.40.0