From a3759c1b25c7dd5b8ec822bf37e6ddd43e3f77ed Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 11 May 2018 13:02:41 +0200 Subject: [PATCH] CODING_STYLE: add section about using strlcpy() Signed-off-by: Christian Brauner --- CODING_STYLE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CODING_STYLE.md b/CODING_STYLE.md index 24c6d3603..784c5134e 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -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.