]> git.ipfire.org Git - thirdparty/git.git/blobdiff - remote.c
use xstrdup_or_null to replace ternary conditionals
[thirdparty/git.git] / remote.c
index 35e62ee0f55cf6c44c0ad94761249ef12b7c19c5..179bceff8a2ce27f95de797656dd5460950c2d9c 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -862,21 +862,14 @@ static int match_name_with_pattern(const char *key, const char *name,
        ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen &&
                !memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
        if (ret && value) {
+               struct strbuf sb = STRBUF_INIT;
                const char *vstar = strchr(value, '*');
-               size_t vlen;
-               size_t vsuffixlen;
                if (!vstar)
                        die("Value '%s' of pattern has no '*'", value);
-               vlen = vstar - value;
-               vsuffixlen = strlen(vstar + 1);
-               *result = xmalloc(vlen + vsuffixlen +
-                                 strlen(name) -
-                                 klen - ksuffixlen + 1);
-               strncpy(*result, value, vlen);
-               strncpy(*result + vlen,
-                       name + klen, namelen - klen - ksuffixlen);
-               strcpy(*result + vlen + namelen - klen - ksuffixlen,
-                      vstar + 1);
+               strbuf_add(&sb, value, vstar - value);
+               strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
+               strbuf_addstr(&sb, vstar + 1);
+               *result = strbuf_detach(&sb, NULL);
        }
        return ret;
 }
@@ -982,8 +975,8 @@ struct ref *copy_ref(const struct ref *ref)
        cpy = xmalloc(sizeof(struct ref) + len + 1);
        memcpy(cpy, ref, sizeof(struct ref) + len + 1);
        cpy->next = NULL;
-       cpy->symref = ref->symref ? xstrdup(ref->symref) : NULL;
-       cpy->remote_status = ref->remote_status ? xstrdup(ref->remote_status) : NULL;
+       cpy->symref = xstrdup_or_null(ref->symref);
+       cpy->remote_status = xstrdup_or_null(ref->remote_status);
        cpy->peer_ref = copy_ref(ref->peer_ref);
        return cpy;
 }