From: Mike Yuan Date: Mon, 11 Mar 2024 10:27:50 +0000 (+0800) Subject: stat-util: struct stat could be initialized with (st_mode & S_IFMT == 0) X-Git-Tag: v256-rc1~570^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=945a8210c770801c8492eda03b6e9af3ec5d03a3;p=thirdparty%2Fsystemd.git stat-util: struct stat could be initialized with (st_mode & S_IFMT == 0) 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. --- diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index ec6273c7d0c..70d5b742241 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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 &&