Re: [PATCH] fetch: convert strncmp() with strlen() to starts_with()

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

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

>> -		     !strncmp(rs->items[i].src,
>> -			      ref_namespace[NAMESPACE_TAGS].ref,
>> -			      strlen(ref_namespace[NAMESPACE_TAGS].ref)))) {
>> +		     starts_with(rs->items[i].src,
>> +				 ref_namespace[NAMESPACE_TAGS].ref))) {
>
> The original tries to check that "namespace" fully matches the
> initial part of .src string, which is exactly what starts_with()
> does.  Makes sense.

There are two more such instances in the codebase, easily found with

        $ cat >contrib/coccinelle/starts_with.cocci <<\-EOF
        @@
        expression string, prefix;
        @@
        - !strncmp(string, prefix, strlen(prefix))
        + starts_with(string, prefix)

        @@
        expression string, prefix;
        @@
        - strncmp(string, prefix, strlen(prefix))
        + !starts_with(string, prefix)
        EOF
        $ make contrib/coccinelle/starts_with.cocci.patch

which finds the one you just fixed (naturally, since the Cocci patch
was written by taking inspiration from your fix).

Here is one in the reftable code.  The other one is in xdiff/ I'd
rather not touch (as starts_with() is probably not available there).

diff -u -p a/reftable/refname.c b/reftable/refname.c
--- a/reftable/refname.c
+++ b/reftable/refname.c
@@ -103,7 +103,7 @@ static int modification_has_ref_with_pre
 			}
 		}
 
-		if (strncmp(ref.refname, prefix, strlen(prefix))) {
+		if (!starts_with(ref.refname, prefix)) {
 			err = 1;
 			goto done;
 		}




[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