From: Junio C Hamano Date: Fri, 08 May 2020 16:38:17 GMT Subject: Re: Re* [PATCH v4] submodule: port subcommand 'set-url' from shell to C Message-ID: In-Reply-To: <20200508161315.GA3504@flurp.local> Eric Sunshine writes: > From: Junio C Hamano > Subject: [PATCH] CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL > > Signed-off-by: Junio C Hamano > Signed-off-by: Eric Sunshine > --- > Documentation/CodingGuidelines | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines > index 390ceece52..6dfc47ed7d 100644 > --- a/Documentation/CodingGuidelines > +++ b/Documentation/CodingGuidelines > @@ -236,6 +236,18 @@ For C programs: > while( condition ) > func (bar+1); > > + - Do not explicitly compare an integral value with constant 0 or '\0', > + or a pointer value with constant NULL. For instance, to validate a > + counted array ptr that has cnt elements, write: I think this should be counted array is initialized but has no elements, write: > + > + if (!ptr || cnt) > + BUG("empty array expected"); > + > + and not: > + > + if (ptr == NULL || cnt != 0); > + BUG("empty array expected"); > + > - We avoid using braces unnecessarily. I.e. > > if (bla) {