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.
This commit is contained in:
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user