Merge pull request #4389 from fufesou/refact/remove_all_assert

remove all assert in non-test code
This commit is contained in:
RustDesk 2023-05-16 15:26:22 +08:00 committed by GitHub
commit 5f0f4957b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 7 deletions

View File

@ -349,7 +349,9 @@ impl Encrypt {
their_pk_b: &[u8],
our_sk_b: &box_::SecretKey,
) -> ResultType<Key> {
assert!(their_pk_b.len() == box_::PUBLICKEYBYTES);
if their_pk_b.len() != box_::PUBLICKEYBYTES {
anyhow::bail!("Handshake failed: pk length {}", their_pk_b.len());
}
let nonce = box_::Nonce([0u8; box_::NONCEBYTES]);
let mut pk_ = [0u8; box_::PUBLICKEYBYTES];
pk_[..].copy_from_slice(their_pk_b);

View File

@ -108,7 +108,7 @@ fn rust_args_to_c_args(args: Vec<String>, outlen: *mut c_int) -> *mut *mut c_cha
// Make sure we're not wasting space.
out.shrink_to_fit();
assert!(out.len() == out.capacity());
debug_assert!(out.len() == out.capacity());
// Get the pointer to our vector.
let len = out.len();
@ -257,7 +257,7 @@ impl FlutterHandler {
/// * `event` - Fields of the event content.
pub fn push_event(&self, name: &str, event: Vec<(&str, &str)>) -> Option<bool> {
let mut h: HashMap<&str, &str> = event.iter().cloned().collect();
assert!(h.get("name").is_none());
debug_assert!(h.get("name").is_none());
h.insert("name", name);
let out = serde_json::ser::to_string(&h).unwrap_or("".to_owned());
Some(
@ -858,7 +858,7 @@ pub mod connection_manager {
impl FlutterHandler {
fn push_event(&self, name: &str, event: Vec<(&str, &str)>) {
let mut h: HashMap<&str, &str> = event.iter().cloned().collect();
assert!(h.get("name").is_none());
debug_assert!(h.get("name").is_none());
h.insert("name", name);
if let Some(s) = GLOBAL_EVENT_STREAM.read().unwrap().get(super::APP_TYPE_CM) {

View File

@ -80,7 +80,7 @@ impl PluginReturn {
if self.is_success() {
(self.code, "".to_owned())
} else {
assert!(!self.msg.is_null());
debug_assert!(!self.msg.is_null(), "msg is null");
let msg = cstr_to_string(self.msg).unwrap_or_default();
free_c_ptr(self.msg as _);
self.msg = null();

View File

@ -109,7 +109,7 @@ impl SharedMemory {
pub fn write(&self, addr: usize, data: &[u8]) {
unsafe {
assert!(addr + data.len() <= self.inner.len());
debug_assert!(addr + data.len() <= self.inner.len());
let ptr = self.inner.as_ptr().add(addr);
let shared_mem_slice = slice::from_raw_parts_mut(ptr, data.len());
shared_mem_slice.copy_from_slice(data);

View File

@ -49,7 +49,7 @@ impl<T: Subscriber + From<ConnInner>> ServiceInner<T> {
for (_, s) in self.new_subscribes.drain() {
self.subscribes.insert(s.id(), s);
}
assert!(self.new_subscribes.is_empty());
debug_assert!(self.new_subscribes.is_empty());
}
#[inline]