mirror of
git://github.com/lxc/lxc
synced 2025-08-31 11:29:33 +00:00
CODING_STYLE: add section about using strlcpy()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user