]> 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>
Thu, 24 Apr 2025 16:32:35 +0000 (18:32 +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>
libmount/src/fs_statmount.c

index 3993c7b69ea16536dcb851c4c97c4dcaa5729cd5..4e98dd775febf77db5c358817f530ce979896033 100644 (file)
@@ -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);