... | ... | @@ -1054,7 +1054,12 @@ if (CONSTANT != my_variable) { } // Good |
|
|
|
|
|
if (my_variable != CONSTANT) { } // Bad
|
|
|
```
|
|
|
|
|
|
* Use `const` type qualifier on pointer parameters when applicable (i.e. when the referenced value remains unchanged)
|
|
|
* Do not use this type qualifier on pass-by-value parameters as it is redundant
|
|
|
```
|
|
|
const char *app__get_log_line(const *module_s); // Good
|
|
|
bool app__is_id_ready(const *module_s, const size_t type_id); // Bad, const type_id is redundant
|
|
|
```
|
|
|
## Validate Pointers
|
|
|
|
|
|
Assuming there is a heavy use of pointers, we want to balance the fundamental checks with those that may actually be useful and create a safer code-base.
|
... | ... | @@ -1078,7 +1083,7 @@ The reasons for not checking the `this_ptr` are: |
|
|
- Each function would have additional brace level (early returns are forbidden due to MISRA/C)
|
|
|
- We consider passing a `NULL` pointer as a user error, and do not believe it adds significant value
|
|
|
|
|
|
```c
|
|
|
```
|
|
|
void my_api(module_s *this_ptr, void *ptr) {
|
|
|
// Not required to check
|
|
|
// if (NULL != this_ptr)
|
... | ... | |