ui/gtk: Fix GTK assertion failure introduced with clipboard fixes
PATCH 1/1 ui/gtk: Fix GTK assertion failure introduced with clipboard fixes
gtk_clipboard_request_targets actually returns n_targets == -1 when targets == NULL instead of zero. This result in failed assertion within GTK:
qemu: Gtk: gtk_targets_include_text:
assertion 'targets != NULL || n_targets == 0' failed
Extend the check to require non-null targets and positive n_targets.
---
Hi,
with my latest gtk-clipboard changes, I introduced the following GTK assertion failures due to unexpected n_targets value returned to callback from gtk_clipboard_request_targets
qemu: Gtk: gtk_targets_include_text:
assertion 'targets != NULL || n_targets == 0' failed
from
gbooleangtk_targets_include_text (GdkAtom *targets,
gint n_targets)
{
gint i;
gboolean result = FALSE;
g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
/* Keep in sync with gtk_target_list_add_text_targets()
*/
init_atoms ();
for (i = 0; i < n_targets; i++)
...
GTK actually returns -1 instead of zero when there are no targets, triggering the assert. The following patch extends the check to non-null targets and positive n_targets to be on the safe side.
--- ui/gtk-clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/gtk-clipboard.c +1 -1
@@ -175,7 +175,7 @@ static void gd_clipboard_owner_change_targets_received_callback( {QemuClipboardInfo *info = (QemuClipboardInfo *)data; -if (n_targets) { +if (targets && n_targets >0 ) {if (gtk_targets_include_text (targets, n_targets)) { info->types[QEMU_CLIPBOARD_TYPE_TEXT ].available = true; }
---
base-commit: 3d626609ccae61a2e552bccd59c7a0931bab8261
change-id: 20260501-clipboard-assert-fix-cc2bf8672eba
Best regards,
Signature · 1 line
Jindrich Makovicka
Hi
Quoted 11 lines · Jindřich Makovička
gtk_clipboard_request_targetsactually returnsn_targets== -1 when targets == NULL instead of zero. This result in failed assertion within GTK:qemu: Gtk:
gtk_targets_include_text:
assertion 'targets != NULL ||n_targets== 0' failedExtend the check to require non-null targets and positive
n_targets.Signed-off-by Jindrich Makovicka <[email protected]>
Quoted 58 lines
---
Hi,with my latest gtk-clipboard changes, I introduced the following GTK assertion failures due to unexpected
n_targetsvalue returned to callback fromgtk_clipboard_request_targetsqemu: Gtk:
gtk_targets_include_text:
assertion 'targets != NULL ||n_targets== 0' failedfrom
gboolean
gtk_targets_include_text(GdkAtom *targets,
gintn_targets)
{
gint i;
gboolean result = FALSE;g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);/* Keep in sync with
gtk_target_list_add_text_targets()
*/init_atoms ();for (i = 0; i <
n_targets; i++)
...GTK actually returns -1 instead of zero when there are no targets, triggering the assert. The following patch extends the check to non-null targets and positive
n_targetsto be on the safe side.--- ui/gtk-clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ui/gtk-clipboard.c +1
-2@@ -175,7 +175,7 @@ static void gd_clipboard_owner_change_targets_received_callback( {QemuClipboardInfo *info = (QemuClipboardInfo *)data; -if (n_targets) { +if (targets && n_targets >0 ) {if (gtk_targets_include_text (targets, n_targets)) { info->types[QEMU_CLIPBOARD_TYPE_TEXT ].available = true; } ---base-commit:
3d626609ccae61a2e552bccd59c7a0931bab8261
change-id: 20260501-clipboard-assert-fix-cc2bf8672ebaBest regards,
--
Jindrich Makovicka