summaryrefslogtreecommitdiff
path: root/Documentation
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-05-14 21:39:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-05-14 21:39:42 (GMT)
commit73d9f96b4790e16335a30380f97d46bd065dc07b (patch)
treea1ede2a3724761fd0ae66546d5eb80e60e603409 /Documentation
parentf9dbe28d62f9d7f110149ba78f4af7ef50ab1181 (diff)
parent5c7bb0146e1971a00308a667cb0424459262c273 (diff)
downloadgit-73d9f96b4790e16335a30380f97d46bd065dc07b.zip
git-73d9f96b4790e16335a30380f97d46bd065dc07b.tar.gz
git-73d9f96b4790e16335a30380f97d46bd065dc07b.tar.bz2
Merge branch 'jc/codingstyle-compare-with-null'
Doc update. * jc/codingstyle-compare-with-null: CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/CodingGuidelines12
1 files changed, 12 insertions, 0 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index a89e8dc..227f46a 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -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) {