Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup

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

 



On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  builtin/rebase.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 77deebc65c..c064909329 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  				branch_name = options.head_name;
>  
>  		} else {
> -			free(options.head_name);
> -			options.head_name = NULL;
> +			FREE_AND_NULL(options.head_name);
>  			branch_name = "HEAD";
>  		}
>  		if (get_oid("HEAD", &options.orig_head))
> @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  	 * we just fast-forwarded.
>  	 */
>  	strbuf_reset(&msg);
> -	if (!oidcmp(&merge_base, &options.orig_head)) {
> +	if (oideq(&merge_base, &options.orig_head)) {
>  		printf(_("Fast-forwarded %s to %s.\n"),
>  			branch_name, options.onto_name);
>  		strbuf_addf(&msg, "rebase finished: %s onto %s",

You are already using Coccinelle v1.0.7, aren't you?

For some reason previous versions don't notice these two
transformations.  I have patches with these transformations lying
around here for some time now, but haven't submitted them yet, because
I don't really like the way I run Coccinelle v1.0.7 in our static
analysis CI build jobs [1]

Anyway, here are my commit messages for these transformations, please
feel free to re-use them:

  -- >8 --

Subject: builtin rebase: use oideq()

Use oideq() instead of !oidcmp(), as it is more idiomatic, and might
give the compiler more opportunities to optimize.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

  -- 8< --

Subject: builtin rebase: use FREE_AND_NULL
    
Use the macro FREE_AND_NULL to release memory allocated for
'head_name' and clear its pointer.
    
Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

  -- >8 --


[1] https://github.com/szeder/git/commits/travis-coccinelle




[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