From: Karel Zak Date: Thu, 24 Apr 2025 16:32:35 +0000 (+0200) Subject: libmount: avoid calling memset() unnecessarily X-Git-Tag: v2.41.1~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15f72204593e529bff11115e4703c48c4b2c3ea3;p=thirdparty%2Futil-linux.git 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 (cherry picked from commit 9e96e6ed9cce4cbaf3b9ca6e61d0b0ee070685e9) --- diff --git a/libmount/src/fs_statmount.c b/libmount/src/fs_statmount.c index a998ee23c..31982f4a2 100644 --- a/libmount/src/fs_statmount.c +++ b/libmount/src/fs_statmount.c @@ -360,7 +360,11 @@ 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 = sys_statmount(fs->uniq_id, 0, mask, &fs->stmnt->buf, &fs->stmnt->bufsiz, 0); buf = fs->stmnt->buf;