Skip to content

Commit

Permalink
Use an assert to ensure error code is always > 0, and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Dec 30, 2024
1 parent fcfc287 commit 466def3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/proj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ pub(crate) unsafe fn _string(raw_ptr: *const c_char) -> Result<String, str::Utf8

/// Look up an error message using the error code
fn error_message(code: c_int) -> Result<String, str::Utf8Error> {
// Ensure that if we ever get a 0 error code back from libroj, we throw an error
// the minimum error code should be 1024
assert_ne!(code, 0);
unsafe {
let rv = proj_errno_string(code);
_string(rv)
Expand Down Expand Up @@ -1484,4 +1487,10 @@ mod test {
assert_eq!(area.north, 84.73);
assert!(name.contains("Europe"));
}

#[test]
#[should_panic]
fn error_message_zero_code() {
assert!(error_message(0).is_err());
}
}

0 comments on commit 466def3

Please sign in to comment.