Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null pointer when attempting to build an error string #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading