[[PATCH v2] 1/2] bcachefs: replace strncpy() with memcpy_and_pad in journal_transaction_name

From: Roxana Nicolescu
Date: Thu Mar 27 2025 - 08:53:40 EST


Strncpy is now deprecated.
The buffer destination is not required to be NULL-terminated, but we also
want to zero out the rest of the buffer as it is already done in other
places.

Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Roxana Nicolescu <nicolescu.roxana@xxxxxxxxxxxxxx>
---
fs/bcachefs/btree_trans_commit.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
index c4f524b2ca9a..794b70cc98d7 100644
--- a/fs/bcachefs/btree_trans_commit.c
+++ b/fs/bcachefs/btree_trans_commit.c
@@ -364,7 +364,8 @@ 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));
+ memcpy_and_pad(l->d, JSET_ENTRY_LOG_U64s * sizeof(u64),
+ trans->fn, strlen(trans->fn), 0);
}

static inline int btree_key_can_insert(struct btree_trans *trans,
--
2.34.1