]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/codingstyle-compare-with-null'
authorJunio C Hamano <gitster@pobox.com>
Thu, 14 May 2020 21:39:42 +0000 (14:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 May 2020 21:39:42 +0000 (14:39 -0700)
Doc update.

* jc/codingstyle-compare-with-null:
  CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL

Documentation/CodingGuidelines

index a89e8dcfbc70541280173973acff2020e6e92fb6..227f46ae403ea85a1bea17892aa4b038820b5f9b 100644 (file)
@@ -232,6 +232,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) {