[Spice-devel] [spice-gtk v2] clipboard: Return early on fixup_clipboard_text errors()

Christophe Fergeau cfergeau at redhat.com
Thu Sep 1 14:05:44 UTC 2016


5c8f400 "clipboard: Add clipboard_atom_to_vdagent_type helper"
mistakenly removed some early returns when text conversion fails for
some reason. This commit readds it.
---
Maybe this... Not really convinced. An alternative would be to g_strdup(text)
when we don't convert, but that's a fairly useless string duplication.

Christophe

 src/spice-gtk-session.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 5766bbd..d29bf92 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -967,7 +967,6 @@ static char *fixup_clipboard_text(SpiceGtkSession *self, const char *text, int *
     char *conv = NULL;
     int new_len = *len;
 
-
     if (spice_main_agent_test_capability(self->priv->main, VD_AGENT_CAP_GUEST_LINEEND_CRLF)) {
         GError *err = NULL;
 
@@ -975,6 +974,7 @@ static char *fixup_clipboard_text(SpiceGtkSession *self, const char *text, int *
         if (err) {
             g_warning("Failed to convert text line ending: %s", err->message);
             g_clear_error(&err);
+            *len = -1;
             return NULL;
         }
 
@@ -992,6 +992,7 @@ static char *fixup_clipboard_text(SpiceGtkSession *self, const char *text, int *
 
     if (!check_clipboard_size_limits(self, new_len)) {
         g_free(conv);
+        *len = -1;
         return NULL;
     }
 
@@ -1026,6 +1027,9 @@ static void clipboard_received_text_cb(GtkClipboard *clipboard,
 
     /* gtk+ internal utf8 newline is always LF, even on windows */
     conv = fixup_clipboard_text(self, text, &len);
+    if (len == -1) {
+        return;
+    }
 
     spice_main_clipboard_selection_notify(self->priv->main, selection,
                                           VD_AGENT_CLIPBOARD_UTF8_TEXT,
-- 
2.7.4



More information about the Spice-devel mailing list