https://bugs.kde.org/show_bug.cgi?id=392959

            Bug ID: 392959
           Summary: Invalid QString conversion in TreeModel.data.fieldname
           Product: rust-qt-binding-generator
           Version: unspecified
          Platform: Other
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: j...@vandenoever.info
          Reporter: kdebuac....@porcupinefactory.org
  Target Milestone: ---

Trying to implement an object backing a tree model, I found that QString
contents of a requested field (Bookmarks::data() -> String) were passed in an
invalid way across the C/C++ boundary.

The issue was that interface::QString was converted wrong into qstring_t, with
mismatched pointer dereferences.

The object in question:

"Bookmarks": {
            "type": "Tree",
            "itemProperties": {
                "type_": {
                    "type": "quint32",
                    "roles": [ ["toolTip"] ]
                },
                "name": {
                    "type": "QString",
                    "roles": [ ["display"] ]
                },
                "count": {
                    "type": "quint32",
                    "roles": [ [], ["display"] ]
                }
            }
        }

The affected field was `name`, thus the invalid function to read it:

#[no_mangle]
pub unsafe extern "C" fn bookmarks_data_name(
    ptr: *const Bookmarks, item: usize,
    d: *mut c_void,
    set: fn(*mut c_void, QString),
) {
    let data = (&*ptr).name(item);
    set(d, (data).into());
}

The fixed function:

#[no_mangle]
pub unsafe extern "C" fn bookmarks_data_name(
    ptr: *const Bookmarks, item: usize,
    d: *mut c_void,
    set: fn(*mut c_void, &QString), // added pointer
) {
    let data = (&*ptr).name(item);
    let qs = (data).into();
    set(d, &qs); // should be safe; a copy is made on the other side
}

The code to generate this is around line 360 in src/rust.cpp. The other side is
line 932 in src/cpp.cpp

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to