Skip to content

Commit

Permalink
Return Error on invalid offset instead of panic'ing
Browse files Browse the repository at this point in the history
  • Loading branch information
int08h committed Mar 19, 2018
1 parent f80c952 commit 1ce57a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub enum Error {
/// Request was less than 1024 bytes
RequestTooShort,

/// Offset within message was not 32-bit aligned
InvalidOffsetAlignment(u32),

/// Otherwise invalid request
InvalidRequest,
}
Expand Down
2 changes: 1 addition & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl RtMessage {
for _ in 0..num_tags - 1 {
let offset = msg.read_u32::<LittleEndian>()?;
if offset % 4 != 0 {
panic!("Invalid offset {:?} in message {:?}", offset, bytes);
return Err(Error::InvalidOffsetAlignment(offset));
}
offsets.push(offset as usize);
}
Expand Down

0 comments on commit 1ce57a1

Please sign in to comment.