From 81404db80bbf9463c3d535ae389e7fbb753a902c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 17 Dec 2024 20:30:13 +0100 Subject: update contributing.md --- contributing.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'contributing.md') diff --git a/contributing.md b/contributing.md index 0faed2b..5555892 100644 --- a/contributing.md +++ b/contributing.md @@ -827,6 +827,32 @@ that you can click on to open them. int bar = foo[0]; ``` +-
+ Always explicitly check against NULL (for C APIs) or + nullptr (for C++ APIs) when checking if a pointer is valid +
GoodBad
+ + ```cpp + string foo = "Hello world"; + if (foo.c_str() == nullptr) + // ... + + void * bar = malloc(); + if (bar == NULL) + // ... + ``` + + + ```cpp + string foo = "Hello world"; + if (!foo.c_str()) + // ... + + void * bar = malloc(); + if (!bar) + // ... + ``` +
## CMakeLists-specific -- cgit v1.2.3