Skip to content

Commit 5c7bb01

Browse files
committed
CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6b65d commit 5c7bb01

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ For C programs:
238238
while( condition )
239239
func (bar+1);
240240

241+
- Do not explicitly compare an integral value with constant 0 or '\0',
242+
or a pointer value with constant NULL. For instance, to validate that
243+
counted array <ptr, cnt> is initialized but has no elements, write:
244+
245+
if (!ptr || cnt)
246+
BUG("empty array expected");
247+
248+
and not:
249+
250+
if (ptr == NULL || cnt != 0);
251+
BUG("empty array expected");
252+
241253
- We avoid using braces unnecessarily. I.e.
242254

243255
if (bla) {

0 commit comments

Comments
 (0)