Re: [PATCH 01/23] contrib/coccinnelle: add equals-null.cocci

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

 



On Sat, Apr 30, 2022 at 05:20:03PM -0700, Junio C Hamano wrote:
> diff -u -p a/compat/mkdir.c b/compat/mkdir.c
> --- a/compat/mkdir.c
> +++ b/compat/mkdir.c
> @@ -9,7 +9,7 @@ int compat_mkdir_wo_trailing_slash(const
>  	size_t len = strlen(dir);
>  
>  	if (len && dir[len-1] == '/') {
> -		if ((tmp_dir = strdup(dir)) == NULL)
> +		if (!(tmp_dir = strdup(dir)))

did not check them all, but wanted to raise that this specific case, seems
to be regressing in readability.

sure; it fails another rule of "not doing assignments inside if", but maybe
when it was introduced with 0539ecfdfce (compat: some mkdir() do not like a
slash at the end, 2012-08-24), that wasn't valid or it was considered ok
for code in compat.

but more importantly it serves as an example of why most of those rules
use "try"; after all the assignment WITH the parenthesis and == is clear
enough that might not warrant the need of two lines, but without the ==
it is likely to cause trouble or confuse someone.

Carlo



[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