Skip to contentSkip to conversation

ui/gtk: Fix GTK assertion failure introduced with clipboard fixes

PATCH In review Jindřich Makovička 2 participants 2 messages May 1

lore
Share & tools
lore
#0 lore raw

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

gboolean
gtk_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
index 463ed4e905..ea9444be70 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 11 lines · Jindřich Makovička

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.

Quoted 58 lines

---
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

gboolean
gtk_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 -2
index 463ed4e905..ea9444be70 100644
@@ -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,
--
Jindrich Makovicka