Skip to contentSkip to conversation

Removing deprecated strncpy()

PATCH In review Kevin Paul Reddy Janagari 2 participants 2 messages Apr 11, 2025

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

PATCH 1/1 Removing deprecated strncpy()

This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarntee NULL termination,
The function adds zero pads which isn't really convenient for short strings as it may cause performce issues

strscpy() is a preffered replacement because it overcomes the limitations of strncpy mentioned above

Compile Tested

---
 net/tipc/node.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/node.c +1 -1
index ccf5e427f43e..cb43f2016a70 100644
@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,
 	tipc_node_read_lock(node);
 	link = node->links[bearer_id].link;
 	if (link) {
-		strncpy(linkname, tipc_link_name(link), len);
+		strscpy(linkname, tipc_link_name(link), len);
 		err = 0;
 	}
 	tipc_node_read_unlock(node);
Signature · 1 line
2.39.5
#1 lore raw
Quoted 8 lines

This patch suggests the replacement of strncpy with strscpy as per Documentation/process/deprecated.
The strncpy() fails to guarntee NULL termination, The function adds zero pads which isn't really convenient for short strings as it may cause performce issues

strscpy() is a preffered replacement because it overcomes the limitations of strncpy mentioned above

Please read my comment for your previous patch:
- Add "net-next" to your email subject like this: [PATCH net-next]
- Fix many typos in your changelog: guarntee -> guarantee, performce --> performance, preffered --> preferred

Quoted 12 lines

Compile Tested

---
net/tipc/node.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/node.c index renamed from net/tipc/node.c +0 -0

ccf5e427f43e..cb43f2016a70 100644

net/tipc/node.c int tipc_node_get_linkname(struct net *net, u32 · line 1585

Quoted 6 lines
net/tipc/node.c +1 -1
@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32
 bearer_id, u32 addr,
 	tipc_node_read_lock(node);
 	link = node->links[bearer_id].link;
 	if (link) {
-		strncpy(linkname, tipc_link_name(link), len);
+		strscpy(linkname, tipc_link_name(link), len);

please merge this change into your previous patch. We do not need a separate patch for the same purpose.