summaryrefslogtreecommitdiff
path: root/Documentation/CodingGuidelines
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-05-08 17:51:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-05-08 18:25:12 (GMT)
commit5c7bb0146e1971a00308a667cb0424459262c273 (patch)
tree78f16634cd2c90e9361d3592a9b2630bb1577f2a /Documentation/CodingGuidelines
parentaf6b65d45ef179ed52087e80cb089f6b2349f4ec (diff)
downloadgit-5c7bb0146e1971a00308a667cb0424459262c273.zip
git-5c7bb0146e1971a00308a667cb0424459262c273.tar.gz
git-5c7bb0146e1971a00308a667cb0424459262c273.tar.bz2
CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
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>
Diffstat (limited to 'Documentation/CodingGuidelines')
-rw-r--r--Documentation/CodingGuidelines12
1 files changed, 12 insertions, 0 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index ed4e443..099968d 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 <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) {