diff --git a/src/dirent.rs b/src/dirent.rs index 17c6ddb23f..1bbbb92f99 100644 --- a/src/dirent.rs +++ b/src/dirent.rs @@ -180,12 +180,15 @@ impl<'a, B: Buffer<'a>> DirentBuf { } pub fn entry(&mut self, entry: DirEntry<'_>) -> Result<()> { let name16 = u16::try_from(entry.name.len()).map_err(|_| Error::new(EINVAL))?; + let record_align = align_of::<*const DirentHeader>(); let record_len = self .header_size .checked_add(name16) // XXX: NUL byte. Unfortunately this is probably the only performant way to be // compatible with C. .and_then(|l| l.checked_add(1)) + // Align length so next header is aligned + .and_then(|l| l.checked_next_multiple_of(record_align as u16)) .ok_or(Error::new(ENAMETOOLONG))?; let [this, remaining] = core::mem::replace(&mut self.buffer, B::empty()) @@ -215,7 +218,7 @@ impl<'a, B: Buffer<'a>> DirentBuf { })?; this_header_extra.zero_out()?; this_name.copy_from_slice_exact(entry.name.as_bytes())?; - this_name_nul.copy_from_slice_exact(&[0])?; + this_name_nul.zero_out()?; self.written += usize::from(record_len); self.buffer = remaining;