File tree Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -658,13 +658,21 @@ impl<T: TransparentPtrType> PtrSlice<T> {
658
658
/// This is guaranteed to be `NULL`-terminated.
659
659
#[ inline]
660
660
pub fn into_raw ( mut self ) -> * mut <T as GlibPtrDefault >:: GlibType {
661
+ // Make sure to allocate a valid pointer that points to a
662
+ // NULL-pointer.
661
663
if self . len == 0 {
662
- ptr:: null_mut ( )
663
- } else {
664
- self . len = 0 ;
665
- self . capacity = 0 ;
666
- self . ptr . as_ptr ( )
664
+ self . reserve ( 0 ) ;
665
+ unsafe {
666
+ ptr:: write (
667
+ self . ptr . as_ptr ( ) . add ( 0 ) ,
668
+ Ptr :: from ( ptr:: null_mut :: < <T as GlibPtrDefault >:: GlibType > ( ) ) ,
669
+ ) ;
670
+ }
667
671
}
672
+
673
+ self . len = 0 ;
674
+ self . capacity = 0 ;
675
+ self . ptr . as_ptr ( )
668
676
}
669
677
670
678
// rustdoc-stripper-ignore-next
Original file line number Diff line number Diff line change @@ -646,13 +646,18 @@ impl StrV {
646
646
/// This is guaranteed to be `NULL`-terminated.
647
647
#[ inline]
648
648
pub fn into_raw ( mut self ) -> * mut * mut c_char {
649
+ // Make sure to allocate a valid pointer that points to a
650
+ // NULL-pointer.
649
651
if self . len == 0 {
650
- ptr:: null_mut ( )
651
- } else {
652
- self . len = 0 ;
653
- self . capacity = 0 ;
654
- self . ptr . as_ptr ( )
652
+ self . reserve ( 0 ) ;
653
+ unsafe {
654
+ * self . ptr . as_ptr ( ) . add ( 0 ) = ptr:: null_mut ( ) ;
655
+ }
655
656
}
657
+
658
+ self . len = 0 ;
659
+ self . capacity = 0 ;
660
+ self . ptr . as_ptr ( )
656
661
}
657
662
658
663
// rustdoc-stripper-ignore-next
You can’t perform that action at this time.
0 commit comments