Re: Re* [PATCH v4] submodule: port subcommand 'set-url' from shell to C
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 8, 2020, 15:38 UTC
- Message-ID
- <CAPig+cQP_9onrq-z5db1GhXSSHaeKJ+UhNewWP25wLCsMRzSrA@mail.gmail.com>
- In-Reply-To
- <xmqq8si21mlz.fsf_-_@gitster.c.googlers.com>
On Fri, May 8, 2020 at 11:18 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> + - Do not explicitly compare an integral value with constant 0 or a
> + pointer value with constant NULL for equality; just say !value
> + instead. To validate a counted array at ptr that has cnt elements
> + in it, write:
> +
> + if (!ptr || !cnt)
> + BUG("array should not be empty at this point");
> +
> + and not:
> +
> + if (ptr == NULL || cnt == 0);
> + BUG("array should not be empty at this point");This talks only about '=='. People might still use 0 or NULL with '!='. I wonder if the example can include '!=', as well. Perhaps:
if (!ptr)
BUG("...");
if (cnt)
foo(ptr, cnt);instead of:
if (ptr == NULL)
BUG("...");
if (cnt != 0)
foo(ptr, cnt);or something.
Also, would you want to talk about not comparing against NUL character?
if (*s)
foo(s);instead of:
if (*s != '\0')
foo(s);Maybe that's overkill since NUL is an integral value which is already covered by your earlier statement (but perhaps some people would overlook that).