git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
May 2, 2022, 11:07 UTC
Message-ID
<20220502110705.gfdr65dondyigdik@carlos-mbp.lan>
In-Reply-To
<xmqqmtg25cjw.fsf@gitster.g>
On Sat, Apr 30, 2022 at 05:20:03PM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> 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
Previous: Junio C HamanoNext: Elia Pinto
Message 15 of 38 in “add a new coccinelle semantic patch to enforce a”
  1. 00/23 add a new coccinelle semantic patch to enforce aElia Pinto, Apr 30, 2022
  2. 01/23 contrib/coccinnelle: add equals-null.cocciElia Pinto, Apr 30, 2022
  3. Philip OakleyApr 30, 2022
  4. Junio C HamanoApr 30, 2022
  5. Philip OakleyApr 30, 2022
  6. Junio C HamanoApr 30, 2022
  7. Junio C HamanoMay 1, 2022
  8. Elia PintoMay 1, 2022
  9. Philip OakleyMay 1, 2022
  10. Junio C HamanoMay 1, 2022
  11. Elia PintoMay 1, 2022
  12. Junio C HamanoMay 2, 2022
  13. Philip OakleyMay 2, 2022
  14. Junio C HamanoMay 2, 2022
  15. Carlo Marcelo Arenas BelónMay 2, 2022
  16. 02/23 apply.c: Fix coding styleElia Pinto, Apr 30, 2022
  17. 03/23 archive.c: Fix coding styleElia Pinto, Apr 30, 2022
  18. 04/23 blame.c: Fix coding styleElia Pinto, Apr 30, 2022
  19. 05/23 branch.c: Fix coding styleElia Pinto, Apr 30, 2022
  20. 08/23 builtin/clone.c: Fix coding styleElia Pinto, Apr 30, 2022
  21. 07/23 builtin/checkout.c: Fix coding styleElia Pinto, Apr 30, 2022
  22. 06/23 builtin/bisect--helper.c: Fix coding styleElia Pinto, Apr 30, 2022
  23. Christian CouderMay 3, 2022
  24. 09/23 builtin/commit.c: Fix coding styleElia Pinto, Apr 30, 2022
  25. 11/23 builtin/gc.c: Fix coding styleElia Pinto, Apr 30, 2022
  26. 10/23 builtin/diff.c: Fix coding styleElia Pinto, Apr 30, 2022
  27. 12/23 builtin/index-pack.c: Fix coding styleElia Pinto, Apr 30, 2022
  28. 13/23 builtin/log.c: Fix coding styleElia Pinto, Apr 30, 2022
  29. 14/23 builtin/ls-remote.c: Fix coding styleElia Pinto, Apr 30, 2022
  30. 16/23 builtin/pack-redundant.c: Fix coding styleElia Pinto, Apr 30, 2022
  31. 15/23 builtin/mailsplit.c: Fix coding styleElia Pinto, Apr 30, 2022
  32. 18/23 builtin/replace.c: Fix coding styleElia Pinto, Apr 30, 2022
  33. 20/23 builtin/shortlog.c: Fix coding styleElia Pinto, Apr 30, 2022
  34. 19/23 builtin/rev-parse.c: Fix coding styleElia Pinto, Apr 30, 2022
  35. 17/23 builtin/receive-pack.c: Fix coding styleElia Pinto, Apr 30, 2022
  36. 21/23 builtin/tag.c: Fix coding styleElia Pinto, Apr 30, 2022
  37. 23/23 commit-graph.c: Fix coding styleElia Pinto, Apr 30, 2022
  38. 22/23 combine-diff.c: Fix coding styleElia Pinto, Apr 30, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.