mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-23 22:28:08 +00:00
CODING_STYLE: add section about using strlcpy()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
9de31d5a13
commit
a3759c1b25
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user