File tree Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Expand file tree Collapse file tree 3 files changed +23
-16
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 @@ -546,8 +546,6 @@ impl<T: TransparentType> Slice<T> {
546546
547547 // rustdoc-stripper-ignore-next
548548 /// Returns the underlying pointer.
549- ///
550- /// This is guaranteed to be `NULL`-terminated.
551549 #[ inline]
552550 pub fn as_ptr ( & self ) -> * const T :: GlibType {
553551 if self . len == 0 {
@@ -559,8 +557,6 @@ impl<T: TransparentType> Slice<T> {
559557
560558 // rustdoc-stripper-ignore-next
561559 /// Returns the underlying pointer.
562- ///
563- /// This is guaranteed to be `NULL`-terminated.
564560 #[ inline]
565561 pub fn as_mut_ptr ( & mut self ) -> * mut T :: GlibType {
566562 if self . len == 0 {
@@ -572,8 +568,6 @@ impl<T: TransparentType> Slice<T> {
572568
573569 // rustdoc-stripper-ignore-next
574570 /// Consumes the slice and returns the underlying pointer.
575- ///
576- /// This is guaranteed to be `NULL`-terminated.
577571 #[ inline]
578572 pub fn into_raw ( mut self ) -> * mut T :: GlibType {
579573 if self . len == 0 {
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