Skip to content

[BUG] StrV::into_raw() can unexpectedly return NULL  #1733

@sophie-h

Description

@sophie-h

Bug description

    image
        .image_info()
        .key_value
        .as_ref()
        .map(|x| glib::StrV::from_iter(x.keys().map(|x| glib::GString::from(x))))
        .unwrap_or_default()
        .into_raw()

This code can return a null pointer, requiring an extra null check before iterating elements like here

https://gitlab.gnome.org/GNOME/gdk-pixbuf/-/commit/d780857e7903506d03a81cdfc10317ead579d545#357b94dfbd5bdee4c5f3f7b1c0777c2e4011bc87_209_211

I think this should return a direct null pointer, but a pointer to NULL or whatever

https://github.com/gtk-rs/gtk-rs-core/blob/main/glib/src/collections/strv.rs#L650

    // rustdoc-stripper-ignore-next
    /// Consumes the slice and returns the underlying pointer.
    ///
    /// This is guaranteed to be `NULL`-terminated.
    #[inline]
    pub fn into_raw(mut self) -> *mut *mut c_char {
        if self.len == 0 {
            ptr::null_mut()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions