Skip to content

Commit

Permalink
Fix as_bytes() for Option<T> when T is fixed width
Browse files Browse the repository at this point in the history
Previously a length 1 buffer would be returned for the None type,
instead of a length 1 + T::fixed_width().
This did not result in data corruption because the buffer these are
copied into was sized as Option<T>::fixed_width(). Still the
implementation was incorrect.
  • Loading branch information
cberner committed Sep 30, 2023
1 parent d3fa940 commit 2a39fe3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ impl<T: RedbValue> RedbValue for Option<T> {
if let Some(x) = value {
result[0] = 1;
result.extend_from_slice(T::as_bytes(x).as_ref());
} else if let Some(fixed_width) = T::fixed_width() {
result.extend_from_slice(&vec![0; fixed_width]);
}
result
}
Expand Down

0 comments on commit 2a39fe3

Please sign in to comment.