Skip to content

Conversation

@guibescos
Copy link
Contributor

More graceful error handling in load. Now it shouldn't panic if length is not right.

@guibescos guibescos marked this pull request as ready for review August 9, 2022 21:55

/// Interpret the bytes in `data` as a value of type `T`
pub fn load<T: Pod>(data: &[u8]) -> Result<&T, ProgramError> {
try_from_bytes(&data[0..size_of::<T>()]).map_err(|_| ProgramError::InvalidArgument)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: it would be nice to document the exact error conditions here. I think this errors if there aren't enough bytes to read a T in data, but is tolerant of data containing more bytes than needed.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. you can add this comment in a later PR so we don't have to go through another approval / ci if you want.

@guibescos guibescos merged commit 4839435 into main Aug 10, 2022
@guibescos guibescos deleted the load-checks-length branch August 10, 2022 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants