From: Junio C Hamano Date: Fri, 8 May 2020 17:51:21 +0000 (-0400) Subject: CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL X-Git-Tag: v2.27.0-rc0~8^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c7bb0146e1971a00308a667cb0424459262c273;p=thirdparty%2Fgit.git CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL Signed-off-by: Junio C Hamano Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index ed4e443a3c..099968d619 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -238,6 +238,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 that + 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) {