summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2020-05-14 14:39:42 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-05-14 14:39:42 -0700
commit73d9f96b4790e16335a30380f97d46bd065dc07b (patch)
treea1ede2a3724761fd0ae66546d5eb80e60e603409
parentMerge branch 'cw/bisect-replay-with-dos' (diff)
parentCodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL (diff)
downloadtgif-73d9f96b4790e16335a30380f97d46bd065dc07b.tar.xz
Merge branch 'jc/codingstyle-compare-with-null'
Doc update. * jc/codingstyle-compare-with-null: CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
-rw-r--r--Documentation/CodingGuidelines12
1 files changed, 12 insertions, 0 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index a89e8dcfbc..227f46ae40 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) {