From 466def32e5b161129810f3e4a61b0fb08df57526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 30 Dec 2024 16:07:53 +0000 Subject: [PATCH] Use an assert to ensure error code is always > 0, and add a test --- src/proj.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/proj.rs b/src/proj.rs index a24e64b3..3c4ac0fd 100644 --- a/src/proj.rs +++ b/src/proj.rs @@ -177,6 +177,9 @@ pub(crate) unsafe fn _string(raw_ptr: *const c_char) -> Result Result { + // 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) @@ -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()); + } }