diff options
author | Simon Ser <contact@emersion.fr> | 2023-10-02 16:21:10 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-10-04 11:08:58 +0200 |
commit | 3406c1b17a4a7e6d4e2a7d9c1176affa72bce1bc (patch) | |
tree | decc11d041feaf8eb0923d77585f5a73f1736c92 | |
parent | 1b0694b79481643cb456d03e1be50a1b4f6ca591 (diff) |
contributing: add safety section
-rw-r--r-- | CONTRIBUTING.md | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2c234273..3d13f5fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -237,6 +237,15 @@ used and `#undef` them after. * Document the contents and container of a `struct wl_list` with a `// content.link` and `// container.list` comment. +### Safety + +* Avoid string manipulation functions which don't take the size of the + destination buffer as input: for instance, prefer `snprintf` over `sprintf`. +* Avoid repeating type names in `sizeof()` where possible. For instance, prefer + `ptr = calloc(1, sizeof(*ptr))` over `ptr = calloc(1, sizeof(struct foo))`. +* Prefer `*ptr = (struct foo){0}` over `memset(ptr, 0, sizeof(*ptr))`. +* Prefer `*foo = *bar` over `memcpy(foo, bar, sizeof(*foo))`. + ### Example ```c |