]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
CODING_STYLE: add section about using strlcpy()
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 11 May 2018 11:02:41 +0000 (13:02 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 10 Dec 2018 07:15:00 +0000 (08:15 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
CODING_STYLE.md

index 24c6d3603ef60096c169e45f13660261f54fd465..784c5134ebbcaa8c9313a73702f1d67311fb283c 100644 (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.