CODING_STYLE: add section about using strlcpy()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-05-11 13:02:41 +02:00
parent 9de31d5a13
commit a3759c1b25
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -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.