Skip to content

Commit ebff3b7

Browse files
committed
src/ext.rs: Fix parsing of nanoseconds in timestamps
The operator precedence assumptions were incorrect. The mask itself was being shifted instead of the masked value. Other places where operator precedence is confusing have also been updated to add parentheses. There is a now clippy lint for this too. Fixes: #13 Signed-off-by: Andrew Gunnerson <[email protected]>
1 parent 5401a72 commit ebff3b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ impl ExtMetadata {
11161116

11171117
pub fn size(&self) -> u64 {
11181118
let small = self.inode.as_ptr();
1119-
unsafe { u64::from((*small).i_size) | u64::from((*small).i_size_high) << 32 }
1119+
unsafe { u64::from((*small).i_size) | (u64::from((*small).i_size_high) << 32) }
11201120
}
11211121

11221122
pub fn nlinks(&self) -> u16 {
@@ -1140,7 +1140,7 @@ impl ExtMetadata {
11401140
_ => 0,
11411141
};
11421142

1143-
u32::from(low) | u32::from(high) << 16
1143+
u32::from(low) | (u32::from(high) << 16)
11441144
}
11451145

11461146
pub fn set_uid(&mut self, uid: u32) {
@@ -1164,7 +1164,7 @@ impl ExtMetadata {
11641164
_ => 0,
11651165
};
11661166

1167-
u32::from(low) | u32::from(high) << 16
1167+
u32::from(low) | (u32::from(high) << 16)
11681168
}
11691169

11701170
pub fn set_gid(&mut self, gid: u32) {
@@ -1185,7 +1185,7 @@ impl ExtMetadata {
11851185

11861186
if let Some(e) = extra {
11871187
secs += i64::from(e & EXT4_EPOCH_MASK) << 32;
1188-
nsecs = e & EXT4_NSEC_MASK as u32 >> EXT4_EPOCH_BITS;
1188+
nsecs = (e & EXT4_NSEC_MASK as u32) >> EXT4_EPOCH_BITS;
11891189
}
11901190

11911191
// This inherently can't overflow because of the original u32 types.

0 commit comments

Comments
 (0)