]> git.ipfire.org Git - thirdparty/git.git/commitdiff
CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
authorJunio C Hamano <gitster@pobox.com>
Fri, 8 May 2020 17:51:21 +0000 (13:51 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 May 2020 18:25:12 +0000 (11:25 -0700)
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/CodingGuidelines

index ed4e443a3cd99f8f86b88951e42509f49b14f638..099968d619e3609fb8e3e46e81dd5ca1ee2396ff 100644 (file)
@@ -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 <ptr, cnt> 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) {