Whamcloud - gitweb
libext2fs: fix Coverity type warnings from ext2fs_inode_xtime_set()
authorTheodore Ts'o <tytso@mit.edu>
Mon, 26 May 2025 01:37:38 +0000 (21:37 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 26 May 2025 01:37:38 +0000 (21:37 -0400)
The ext2fs_inode_xtime_set() C preprocessor macro needs to cast to
__u32 before assigning to the time field.

This fixes a number of integer handling issues reported by Coverity.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h

index 301312e..bb2170b 100644 (file)
@@ -619,11 +619,11 @@ static inline __u32 __decode_extra_nsec(__u32 extra)
 do {                                                                         \
        if (ext2fs_inode_includes(ext2fs_inode_actual_size(inode),            \
                                  field ## _extra)) {                         \
-               (inode)->field = (__s32)(sec & 0xfffffff);                    \
+               (inode)->field = (__u32)(sec & 0xfffffff);                    \
                ((struct ext2_inode_large *)(inode))->field ## _extra =       \
                        __encode_extra_time(sec, 0);                          \
        } else {                                                              \
-               (inode)->field = clamp(sec, INT32_MIN, INT32_MAX);            \
+               (inode)->field = (__u32) clamp(sec, INT32_MIN, INT32_MAX);    \
        }                                                                     \
 } while (0)
 #define ext2fs_inode_xtime_get(inode, field)                                 \