Skip to content

Commit

Permalink
Remove null pointer check in favour of assert
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Aug 16, 2021
1 parent dbb86b4 commit 3b57482
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/proj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ pub enum ProjError {
HeaderConversion(#[from] reqwest::header::ToStrError),
#[error("A {0} error occurred for url {1} after {2} retries")]
DownloadError(String, String, u8),
#[error("Got a null pointer while attempting to build an error String")]
NullPointer
}

/// The bounding box of an area of use
Expand Down Expand Up @@ -127,15 +125,13 @@ impl Area {

/// Easily get a String from the external library
pub(crate) unsafe fn _string(raw_ptr: *const c_char) -> Result<String, ProjError> {
if raw_ptr.is_null() {
return Err(ProjError::NullPointer);
}
let c_str = CStr::from_ptr(raw_ptr);
Ok(str::from_utf8(c_str.to_bytes())?.to_string())
}

/// Look up an error message using the error code
fn error_message(code: c_int) -> Result<String, ProjError> {
assert_ne!(code, 0);
unsafe {
let rv = proj_errno_string(code);
_string(rv)
Expand Down

0 comments on commit 3b57482

Please sign in to comment.