From 9e96e6ed9cce4cbaf3b9ca6e61d0b0ee070685e9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 24 Apr 2025 18:32:35 +0200 Subject: [PATCH] libmount: avoid calling memset() unnecessarily This is primarily to satisfy static analyzers, as memset() is defined as a non-null function (although it does nothing when bufsiz=0). Signed-off-by: Karel Zak --- libmount/src/fs_statmount.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libmount/src/fs_statmount.c b/libmount/src/fs_statmount.c index 3993c7b69..4e98dd775 100644 --- a/libmount/src/fs_statmount.c +++ b/libmount/src/fs_statmount.c @@ -360,7 +360,10 @@ int mnt_fs_fetch_statmount(struct libmnt_fs *fs, uint64_t mask) if (fs->stmnt) { DBG(FS, ul_debugobj(fs, " reuse libmnt_stmnt")); - memset(fs->stmnt->buf, 0, fs->stmnt->bufsiz); + + /* note that sys_statmount (re)allocates the buffer */ + if (fs->stmnt->buf && fs->stmnt->bufsiz > 0) + memset(fs->stmnt->buf, 0, fs->stmnt->bufsiz); rc = ul_statmount(fs->uniq_id, 0, mask, &fs->stmnt->buf, &fs->stmnt->bufsiz, 0); -- 2.47.3