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> {
658658 /// This is guaranteed to be `NULL`-terminated.
659659 #[ inline]
660660 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.
661663 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+ }
667671 }
672+
673+ self . len = 0 ;
674+ self . capacity = 0 ;
675+ self . ptr . as_ptr ( )
668676 }
669677
670678 // rustdoc-stripper-ignore-next
Original file line number Diff line number Diff line change @@ -646,13 +646,18 @@ impl StrV {
646646 /// This is guaranteed to be `NULL`-terminated.
647647 #[ inline]
648648 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.
649651 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+ }
655656 }
657+
658+ self . len = 0 ;
659+ self . capacity = 0 ;
660+ self . ptr . as_ptr ( )
656661 }
657662
658663 // rustdoc-stripper-ignore-next
You can’t perform that action at this time.
0 commit comments