CODING_STYLE: add section about using strlcpy()

parent 9de31d5a
......@@ -662,3 +662,13 @@ rules to use them:
#endif
};
```
#### Use `strlcpy()` instead of `strncpy()`
When copying strings always use `strlcpy()` instead of `strncpy()`. The
advantage of `strlcpy()` is that it will always append a `\0` byte to the
string.
Unless you have a valid reason to accept truncation you must check whether
truncation has occurred, treat it as an error, and handle the error
appropriately.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment