]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: struct stat could be initialized with (st_mode & S_IFMT == 0)
authorMike Yuan <me@yhndnzj.com>
Mon, 11 Mar 2024 10:27:50 +0000 (18:27 +0800)
committerMike Yuan <me@yhndnzj.com>
Mon, 11 Mar 2024 14:57:50 +0000 (22:57 +0800)
For anonymous inodes, the result would be 0, but
the struct stat is initialized obviously.
So let's switch to st_dev for the check, which
is guaranteed to be non-zero.

Also this is completely unnecessary for statx(),
since we check stx_mask first and that on its own
denotes that the struct is initialized.

src/basic/stat-util.c

index ec6273c7d0c53310d0c827e2376a2c21a07b18e3..70d5b7422416612a7e9e24270e07a784646fb5c6 100644 (file)
@@ -365,7 +365,7 @@ bool stat_inode_same(const struct stat *a, const struct stat *b) {
          * a thorough check, comparing inode nr, backing device and if the inode is still of the same type. */
 
         return a && b &&
-                (a->st_mode & S_IFMT) != 0 && /* We use the check for .st_mode if the structure was ever initialized */
+                a->st_dev != 0 && /* is the structure ever initialized? */
                 ((a->st_mode ^ b->st_mode) & S_IFMT) == 0 &&  /* same inode type */
                 a->st_dev == b->st_dev &&
                 a->st_ino == b->st_ino;
@@ -395,7 +395,6 @@ bool statx_inode_same(const struct statx *a, const struct statx *b) {
 
         return a && b &&
                 FLAGS_SET(a->stx_mask, STATX_TYPE|STATX_INO) && FLAGS_SET(b->stx_mask, STATX_TYPE|STATX_INO) &&
-                (a->stx_mode & S_IFMT) != 0 &&
                 ((a->stx_mode ^ b->stx_mode) & S_IFMT) == 0 &&
                 a->stx_dev_major == b->stx_dev_major &&
                 a->stx_dev_minor == b->stx_dev_minor &&