From e36421f5d3f363dee5eb665911e08392ee350a8d Mon Sep 17 00:00:00 2001 From: Katherine Kiefer Date: Sun, 31 Mar 2024 00:40:59 +1100 Subject: [PATCH] wrong --- crates/byondapi-rs/Cargo.toml | 2 +- crates/byondapi-rs/src/map.rs | 4 +--- crates/byondapi-rs/src/value/functions.rs | 4 +--- crates/byondapi-rs/src/value/list.rs | 8 ++------ 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/crates/byondapi-rs/Cargo.toml b/crates/byondapi-rs/Cargo.toml index 50dc675..b89b757 100644 --- a/crates/byondapi-rs/Cargo.toml +++ b/crates/byondapi-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "byondapi" -version = "0.4.3" +version = "0.4.4" authors = ["tigercat2000 "] edition = "2021" description = "Idiomatic Rust bindings for BYONDAPI" diff --git a/crates/byondapi-rs/src/map.rs b/crates/byondapi-rs/src/map.rs index e559192..d46fdfe 100644 --- a/crates/byondapi-rs/src/map.rs +++ b/crates/byondapi-rs/src/map.rs @@ -38,7 +38,6 @@ pub fn byond_block(corner1: ByondXYZ, corner2: ByondXYZ) -> Result Result, Error> { - let initial_len = buff.capacity() as u32; let mut len = buff.capacity() as u32; // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound let initial_res = unsafe { @@ -46,8 +45,7 @@ pub fn byond_block(corner1: ByondXYZ, corner2: ByondXYZ) -> Result { - debug_assert!(len > initial_len); - buff.reserve_exact((len - initial_len) as usize); + buff.reserve_exact(len as usize); // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound unsafe { map_byond_error!(byond().Byond_Block( diff --git a/crates/byondapi-rs/src/value/functions.rs b/crates/byondapi-rs/src/value/functions.rs index 4ce9eb1..05ee416 100644 --- a/crates/byondapi-rs/src/value/functions.rs +++ b/crates/byondapi-rs/src/value/functions.rs @@ -42,15 +42,13 @@ impl ByondValue { } let bytes = BUFFER.with_borrow_mut(|buff| -> Result, Error> { - let initial_len = buff.capacity() as u32; let mut len = buff.capacity() as u32; // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound let initial_res = unsafe { byond().Byond_ToString(&self.0, buff.as_mut_ptr().cast(), &mut len) }; match (initial_res, len) { (false, 1..) => { - debug_assert!(len > initial_len); - buff.reserve_exact((len - initial_len) as usize); + buff.reserve_exact(len as usize); // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound unsafe { map_byond_error!(byond().Byond_ToString( diff --git a/crates/byondapi-rs/src/value/list.rs b/crates/byondapi-rs/src/value/list.rs index 8435e83..a93d3bf 100644 --- a/crates/byondapi-rs/src/value/list.rs +++ b/crates/byondapi-rs/src/value/list.rs @@ -13,7 +13,6 @@ impl ByondValue { } BUFFER.with_borrow_mut(|buff| -> Result, Error> { - let initial_len = buff.capacity() as u32; let mut len = buff.capacity() as u32; // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound @@ -21,8 +20,7 @@ impl ByondValue { unsafe { byond().Byond_ReadList(&self.0, buff.as_mut_ptr().cast(), &mut len) }; match (initial_res, len) { (false, 1..) => { - debug_assert!(len > initial_len); - buff.reserve_exact((len - initial_len) as usize); + buff.reserve_exact(len as usize); // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound unsafe { map_byond_error!(byond().Byond_ReadList( @@ -58,7 +56,6 @@ impl ByondValue { } BUFFER.with_borrow_mut(|buff| -> Result, Error> { - let initial_len = buff.capacity() as u32; let mut len = buff.capacity() as u32; // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound @@ -66,8 +63,7 @@ impl ByondValue { unsafe { byond().Byond_ReadListAssoc(&self.0, buff.as_mut_ptr().cast(), &mut len) }; match (initial_res, len) { (false, 1..) => { - debug_assert!(len > initial_len); - buff.reserve_exact((len - initial_len) as usize); + buff.reserve_exact(len as usize); // Safety: buffer capacity is passed to byond, which makes sure it writes in-bound unsafe { map_byond_error!(byond().Byond_ReadListAssoc(