sos-os/kernel

A bunch of improvements to elf::extract_from_slice

hawkw opened this issue · 1 comments

hawkw commented

As of 014adb9, there are a lot of TODOs on this function, so it probably deserves its own issue:

/// TODO: rewrite this as a `TryFrom` implementation (see issue #85)
//          - eliza, 03/09/2017
///       wait, possibly we should NOT do that. actually we should
///       almost certainly not do that. since this function is unsafe,
///       but `TryFrom` is not, and because this would be WAY generic.
//          - eliza, 03/09/2017
/// TODO: is this general enough to move into util?
//          - eliza, 03/09/2017
/// TODO: should this be refactored to return a `Result`?
//          - eliza, 03/13/2017
/// TODO: can we ensure that the lifetime of the returned slice is the same
///       as the lifetime of the input byte slice, rather than inferred by
///       [`slice::from_raw_parts`]?
//          - eliza, 03/13/2017
/// TODO: assert that `offset` is aligned on a `T`-sized boundary
//          - eliza, 03/13/2017
/// TODO: do we want to assert that `offset` is less than the length of `data`
///       separately from asserting that the slice is long enough, so that
///       we can panic with different messages?
//          - eliza, 03/13/2017
///
  • ensure that the lifetime of the returned slice is the same as the lifetime of the input slice
  • assert offset is aligned on a T-sized boundary
  • assert offset is a valid offset into data
  • consider refactoring to return Result
  • consider moving to util crate
hawkw commented

Returns Result as of 5e359b0