Re: [PATCH 3/5] Use the matching function to generate the match results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Barkalow <barkalow@xxxxxxxxxxxx> writes:

> This puts all of the interpretation of the pattern representation in a
> single function for easy manipulation.
>
> Signed-off-by: Daniel Barkalow <barkalow@xxxxxxxxxxxx>

I think this makes sense, but the helper function is not about "does this
name match the pattern?" boolean anymore, and may want to be renamed to
e.g. map_name_with_pattern().

> -static int name_fits_pattern(const char *key, const char *name)
> +static int name_fits_pattern(const char *key, const char *name,
> +			     const char *value, char **result)
>  {
> -	int ret = !prefixcmp(key, name);
> +	size_t klen = strlen(key);
> +	int ret = !strncmp(key, name, klen);
> +	if (ret && value) {
> +		size_t vlen = strlen(value);
> +		*result = xmalloc(vlen +
> +				  strlen(name) -
> +				  klen + 1);
> +		strcpy(*result, value);
> +		strcpy(*result + vlen, name + klen);
> +	}

> @@ -1080,11 +1085,9 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
>  
>  		} else {
>  			const char *dst_side = pat->dst ? pat->dst : pat->src;
> -			dst_name = xmalloc(strlen(dst_side) +
> -					   strlen(src->name) -
> -					   strlen(pat->src) + 2);
> -			strcpy(dst_name, dst_side);
> -			strcat(dst_name, src->name + strlen(pat->src));
> +			if (!name_fits_pattern(pat->src, src->name,
> +					       dst_side, &dst_name))
> +				die("Didn't think it matches any more");
>  		}

Hmm, we have been overallocating and nobody noticed so far?

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux