mirror of
https://github.com/git/git.git
synced 2024-11-28 12:34:08 +08:00
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>
This commit is contained in:
parent
af6b65d45e
commit
5c7bb0146e
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user