@@ -13,14 +13,16 @@ impl ByondValue {
13
13
}
14
14
15
15
BUFFER . with_borrow_mut ( |buff| -> Result < Vec < ByondValue > , Error > {
16
+ let initial_len = buff. capacity ( ) as u32 ;
16
17
let mut len = buff. capacity ( ) as u32 ;
17
18
18
19
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
19
20
let initial_res =
20
21
unsafe { byond ( ) . Byond_ReadList ( & self . 0 , buff. as_mut_ptr ( ) . cast ( ) , & mut len) } ;
21
22
match ( initial_res, len) {
22
23
( false , 1 ..) => {
23
- buff. reserve_exact ( len as usize ) ;
24
+ debug_assert ! ( len > initial_len) ;
25
+ buff. reserve_exact ( ( len - initial_len) as usize ) ;
24
26
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
25
27
unsafe {
26
28
map_byond_error ! ( byond( ) . Byond_ReadList (
@@ -56,14 +58,16 @@ impl ByondValue {
56
58
}
57
59
58
60
BUFFER . with_borrow_mut ( |buff| -> Result < Vec < ByondValue > , Error > {
61
+ let initial_len = buff. capacity ( ) as u32 ;
59
62
let mut len = buff. capacity ( ) as u32 ;
60
63
61
64
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
62
65
let initial_res =
63
66
unsafe { byond ( ) . Byond_ReadListAssoc ( & self . 0 , buff. as_mut_ptr ( ) . cast ( ) , & mut len) } ;
64
67
match ( initial_res, len) {
65
68
( false , 1 ..) => {
66
- buff. reserve_exact ( len as usize ) ;
69
+ debug_assert ! ( len > initial_len) ;
70
+ buff. reserve_exact ( ( len - initial_len) as usize ) ;
67
71
// Safety: buffer capacity is passed to byond, which makes sure it writes in-bound
68
72
unsafe {
69
73
map_byond_error ! ( byond( ) . Byond_ReadListAssoc (
0 commit comments