Skip to contentSkip to conversation

bcachefs: replace deprecated strncpy with strscpy

PATCH In review Daniel Yang 2 participants 3 messages Nov 13, 2024 – Nov 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: replace deprecated strncpy with strscpy

The function strncpy is deprecated due to not guaranteeing the destination buffer will be NULL-terminated. The recommended replacement is to use strscpy().

---
 fs/bcachefs/btree_trans_commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/btree_trans_commit.c +1 -1
index 9bf471fa4..37e98695b 100644
@@ -364,7 +364,7 @@ static noinline void journal_transaction_name(struct btree_trans *trans)
 	struct jset_entry_log *l =
 		container_of(entry, struct jset_entry_log, entry);
 
-	strncpy(l->d, trans->fn, JSET_ENTRY_LOG_U64s * sizeof(u64));
+	strscpy(l->d, trans->fn, JSET_ENTRY_LOG_U64s * sizeof(u64));
 }
 
 static inline int btree_key_can_insert(struct btree_trans *trans,
Signature · 1 line
2.39.5
#1 lore raw
Quoted 3 lines · Daniel Yang

The function strncpy is deprecated due to not guaranteeing the destination buffer will be NULL-terminated. The recommended replacement is to use strscpy().

strncpy is correct here, we don't need the output to be nul terminated

#2 lore raw
Quoted 1 line · Kent Overstreet

strncpy is correct here, we don't need the output to be nul terminated

If dest is not NULL terminated, then core API recommends using strtomem instead.