Skip to content

Commit

Permalink
Fix coverity false positives introduced by the post-2038 changes
Browse files Browse the repository at this point in the history
Commit ca8bc92 ("Add post-2038 timestamp support...") did things
like casting a 64-bit unsigned integer into a signed 32-bit integer
deliberately; but Coverity thinks this is a bug.  So mask off the bits
to make it clear this was deliberate.

Addresses-Coverity-Bug: 1596519
Addresses-Coverity-Bug: 1596515
Addresses-Coverity-Bug: 1596514
Addresses-Coverity-Bug: 1596513
Addresses-Coverity-Bug: 1596511
Addresses-Coverity-Bug: 1596509
Addresses-Coverity-Bug: 1596508
Addresses-Coverity-Bug: 1596504
Addresses-Coverity-Bug: 1596502
Addresses-Coverity-Bug: 1596501
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Apr 24, 2024
1 parent a12302f commit ec1c87f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/ext2fs/ext2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ static inline __u32 __encode_extra_time(time_t seconds, __u32 nsec)
__u32 extra = 0;

#if (SIZEOF_TIME_T > 4)
extra = ((seconds - (__s32)seconds) >> 32) & EXT4_EPOCH_MASK;
extra = ((seconds - (__s32)(seconds & 0xffffffff)) >> 32) &
EXT4_EPOCH_MASK;
#endif
return extra | (nsec << EXT4_EPOCH_BITS);
}
Expand All @@ -610,7 +611,7 @@ static inline __u32 __decode_extra_nsec(__u32 extra)
do { \
if (ext2fs_inode_includes(ext2fs_inode_actual_size(inode), \
field ## _extra)) { \
(inode)->field = (__s32)sec; \
(inode)->field = (__s32)(sec & 0xfffffff); \
((struct ext2_inode_large *)(inode))->field ## _extra = \
__encode_extra_time(sec, 0); \
} else { \
Expand All @@ -627,7 +628,7 @@ static inline void __sb_set_tstamp(__u32 *lo, __u8 *hi, time_t seconds)
{
*lo = seconds & 0xffffffff;
#if (SIZEOF_TIME_T > 4)
*hi = seconds >> 32;
*hi = (seconds >> 32) & EXT4_EPOCH_MASK;
#else
*hi = 0;
#endif
Expand Down

0 comments on commit ec1c87f

Please sign in to comment.