Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Optimized cache a little bit which saves ~200 bytes binary size in example
- Add heap-backed cache types when the `alloc` feature is active.
This gets rid of some (const) generics and allows you to create a cache with dynamic length.
- Added checks to avoid trying to write or read zero bytes of data to/from the flash

This release is 'disk'-compatible with 6.0

Expand Down
36 changes: 20 additions & 16 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,16 @@ impl ItemHeader {

let mut retry = false;
loop {
flash
.read(data_address, &mut data_buffer[..read_len])
.await
.map_err(|e| Error::Storage {
value: e,
#[cfg(feature = "_test")]
backtrace: std::backtrace::Backtrace::capture(),
})?;
if read_len != 0 {
flash
.read(data_address, &mut data_buffer[..read_len])
.await
.map_err(|e| Error::Storage {
value: e,
#[cfg(feature = "_test")]
backtrace: std::backtrace::Backtrace::capture(),
})?;
}

let data = &data_buffer[..self.length as usize];
let data_crc = adapted_crc32(data);
Expand Down Expand Up @@ -290,14 +292,16 @@ impl<'d> Item<'d> {
};

let data_address = ItemHeader::data_address::<S>(address);
flash
.write(data_address, data_block)
.await
.map_err(|e| Error::Storage {
value: e,
#[cfg(feature = "_test")]
backtrace: std::backtrace::Backtrace::capture(),
})?;
if !data_block.is_empty() {
flash
.write(data_address, data_block)
.await
.map_err(|e| Error::Storage {
value: e,
#[cfg(feature = "_test")]
backtrace: std::backtrace::Backtrace::capture(),
})?;
}

if !data_left.is_empty() {
let mut buffer = AlignedBuf([0; MAX_WORD_SIZE]);
Expand Down
2 changes: 1 addition & 1 deletion src/mock_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<const PAGES: usize, const BYTES_PER_WORD: usize, const PAGE_WORDS: usize>

fn validate_operation(offset: u32, length: usize) -> Result<Range<usize>, MockFlashError> {
let offset = offset as usize;
if (offset % Self::READ_SIZE) != 0 {
if (offset % Self::READ_SIZE) != 0 || length == 0 || length % BYTES_PER_WORD != 0 {
Err(MockFlashError::NotAligned)
} else if offset > Self::CAPACITY_BYTES || offset + length > Self::CAPACITY_BYTES {
Err(MockFlashError::OutOfBounds)
Expand Down
Loading