[Spice-devel,spice-gtk,v1,3/7] gtk-session: use clear variable for array's size

Submitted by Victor Toso on Feb. 22, 2017, 1:11 p.m.

Details

Message ID 20170222131112.14079-4-victortoso@redhat.com
State New
Headers show
Series "clipboard_get_targets() on spice-gtk-session.c" ( rev: 4 3 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso Feb. 22, 2017, 1:11 p.m.
From: Victor Toso <me@victortoso.com>

There is no need to use an index variable to keep track of the number
of VD_AGENT_CLIPBOARD types we are storing.

Signed-off-by: Victor Toso <victortoso@redhat.com>
---
 src/spice-gtk-session.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index bc47f6b..cda2c3a 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -615,6 +615,7 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
     char *name;
     int a, m, t;
     int selection;
+    gint num_types;
 
     if (s->main == NULL)
         return;
@@ -631,6 +632,8 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
         }
     }
 
+    /* Set all Atoms that matches our current protocol implementation */
+    num_types = 0;
     for (a = 0; a < n_atoms; a++) {
         name = gdk_atom_name(atoms[a]);
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
@@ -646,6 +649,7 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
                 if (types[t] == 0) {
                     /* add type to empty slot */
                     types[t] = atom2agent[m].vdagent;
+                    num_types++;
                     break;
                 }
             }
@@ -653,16 +657,17 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
         }
         g_free(name);
     }
-    for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) {
-        if (types[t] == 0) {
-            break;
-        }
+
+    if (num_types == 0) {
+        SPICE_DEBUG("No GdkAtoms will be sent from %d", n_atoms);
+        return;
     }
-    if (!s->clip_grabbed[selection] && t > 0) {
+
+    if (!s->clip_grabbed[selection]) {
         s->clip_grabbed[selection] = TRUE;
 
         if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
-            spice_main_clipboard_selection_grab(s->main, selection, types, t);
+            spice_main_clipboard_selection_grab(s->main, selection, types, num_types);
         /* Sending a grab causes the agent to do an implicit release */
         s->nclip_targets[selection] = 0;
     }