Skip to content

Commit 8c4b10d

Browse files
committed
glib: collections: Change early return to assertion in collection reserve functions
On early return this would cause out of bounds writes from the caller, and this condition should never really happen.
1 parent cb07b5e commit 8c4b10d

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

glib/src/collections/ptr_slice.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,7 @@ impl<T: TransparentPtrType> PtrSlice<T> {
707707
let new_capacity =
708708
usize::next_power_of_two(std::cmp::max(self.len + additional, MIN_SIZE) + 1);
709709
assert_ne!(new_capacity, 0);
710-
711-
if new_capacity <= self.capacity {
712-
return;
713-
}
710+
assert!(new_capacity > self.capacity);
714711

715712
unsafe {
716713
let ptr = if self.capacity == 0 {

glib/src/collections/slice.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,7 @@ impl<T: TransparentType> Slice<T> {
623623
MIN_SIZE / mem::size_of::<T>(),
624624
));
625625
assert_ne!(new_capacity, 0);
626-
627-
if new_capacity <= self.capacity {
628-
return;
629-
}
626+
assert!(new_capacity > self.capacity);
630627

631628
unsafe {
632629
let ptr = if self.capacity == 0 {

glib/src/collections/strv.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,7 @@ impl StrV {
667667
let new_capacity =
668668
usize::next_power_of_two(std::cmp::max(self.len + additional, MIN_SIZE) + 1);
669669
assert_ne!(new_capacity, 0);
670-
671-
if new_capacity <= self.capacity {
672-
return;
673-
}
670+
assert!(new_capacity > self.capacity);
674671

675672
unsafe {
676673
let ptr = if self.capacity == 0 {

0 commit comments

Comments
 (0)