Skip to contentSkip to conversation

kconfig/nconf: Replace deprecated strncpy() with strscpy()

PATCH New Shankari Anand 1 participant 1 message May 21, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig/nconf: Replace deprecated strncpy() with strscpy()

The use of strncpy() does not guarantee null-termination and is deprecated in the kernel. This change replaces it with strscpy(), which ensures null-termination and returns a value indicating truncation.

In this case, padding the destination buffer is not necessary since the string is used in a UI context as a null-terminated string. Therefore, strscpy() is a safer and more efficient replacement. See: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

---
 scripts/kconfig/nconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/nconf.c +1 -1
index c0b2dabf6c89..67ee33fe16ef 100644
@@ -589,7 +589,7 @@ static void item_add_str(const char *fmt, ...)
 	va_end(ap);
 	snprintf(tmp_str, sizeof(tmp_str), "%s%s",
 			k_menu_items[index].str, new_str);
-	strncpy(k_menu_items[index].str,
+	strscpy(k_menu_items[index].str,
 		tmp_str,
 		sizeof(k_menu_items[index].str));
 
Signature · 1 line
2.34.1