]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: avoid calling memset() unnecessarily
authorKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2025 16:32:35 +0000 (18:32 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 25 Apr 2025 08:43:13 +0000 (10:43 +0200)
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 <kzak@redhat.com>
(cherry picked from commit 9e96e6ed9cce4cbaf3b9ca6e61d0b0ee070685e9)

libmount/src/fs_statmount.c

index a998ee23cfafe243366e511a58e2f65a2e3f165f..31982f4a2439ddcba1be4c2951b1793a0d1af664 100644 (file)
@@ -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;