]> git.proxmox.com Git - mirror_lxc.git/blobdiff - CODING_STYLE.md
Merge pull request #2486 from 2xsec/bugfix
[mirror_lxc.git] / CODING_STYLE.md
index 24c6d3603ef60096c169e45f13660261f54fd465..7f2df9ed2c178637eb5679e8c89523ded2de5267 100644 (file)
@@ -662,3 +662,23 @@ 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.
+
+#### Use `strlcat()` instead of `strncat()`
+
+When concatenating strings always use `strlcat()` instead of `strncat()`. The
+advantage of `strlcat()` 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.