Skip to content

Commit 021c59f

Browse files
committed
Fix typo and invariant
1 parent 2d734df commit 021c59f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

library/core/src/ffi/c_str.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::ptr::NonNull;
99
use crate::slice::memchr;
1010
use crate::{fmt, intrinsics, ops, slice, str};
1111

12-
// use safety::{requires, ensures};
1312
use crate::ub_checks::Invariant;
1413

1514
#[cfg(kani)]
@@ -217,19 +216,15 @@ impl fmt::Display for FromBytesWithNulError {
217216
impl Invariant for &CStr {
218217
/**
219218
* Safety invariant of a valid CStr:
220-
* 1. An empty CStr should has a null byte.
219+
* 1. An empty CStr should have a null byte.
221220
* 2. A valid CStr should end with a null-terminator and contains
222221
* no intermediate null bytes.
223222
*/
224223
fn is_safe(&self) -> bool {
225224
let bytes: &[c_char] = &self.inner;
226225
let len = bytes.len();
227226

228-
if bytes.is_empty() || bytes[len - 1] != 0 || bytes[..len-1].contains(&0) {
229-
return false;
230-
}
231-
232-
true
227+
return !bytes.is_empty() && bytes[len - 1] == 0 && !bytes[..len-1].contains(&0);
233228
}
234229
}
235230

0 commit comments

Comments
 (0)