19ccae
From 1573a790da7370f547d542191d530ba8580e5a03 Mon Sep 17 00:00:00 2001
19ccae
From: Frediano Ziglio <freddy77@gmail.com>
19ccae
Date: Mon, 14 Sep 2020 13:51:15 +0100
19ccae
Subject: [PATCH] Fix warning by Coverity
19ccae
19ccae
Error: DEADCODE (CWE-561): [#def1]
19ccae
virt-viewer-9.0/src/virt-viewer-display-vte.c:164: assignment: Assigning: "scroll" = "NULL".
19ccae
virt-viewer-9.0/src/virt-viewer-display-vte.c:188: null: At condition "scroll", the value of "scroll" must be "NULL".
19ccae
virt-viewer-9.0/src/virt-viewer-display-vte.c:188: dead_error_condition: The condition "scroll" cannot be true.
19ccae
virt-viewer-9.0/src/virt-viewer-display-vte.c:189: dead_error_begin: Execution cannot reach this statement: "gtk_container_add((GtkConta...".
19ccae
virt-viewer-9.0/src/virt-viewer-display-vte.c:189: effectively_constant: Local variable "scroll" is assigned only once, to a constant value, making it effectively constant throughout its scope. If this is not the intent, examine the logic to see if there is a missing assignment that would make "scroll" not remain constant.
19ccae
19ccae
Reported in https://gitlab.com/virt-viewer/virt-viewer/-/issues/7.
19ccae
19ccae
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
19ccae
---
19ccae
 src/virt-viewer-display-vte.c | 10 ++++++++--
19ccae
 1 file changed, 8 insertions(+), 2 deletions(-)
19ccae
19ccae
diff --git a/src/virt-viewer-display-vte.c b/src/virt-viewer-display-vte.c
19ccae
index ef0d5ac..9e4f734 100644
19ccae
--- a/src/virt-viewer-display-vte.c
19ccae
+++ b/src/virt-viewer-display-vte.c
19ccae
@@ -147,7 +147,6 @@ virt_viewer_display_vte_commit(VirtViewerDisplayVte *self,
19ccae
 {
19ccae
     g_signal_emit_by_name(self, "commit", text, size);
19ccae
 }
19ccae
-#endif
19ccae
 
19ccae
 static void
19ccae
 virt_viewer_display_vte_adj_changed(VirtViewerDisplayVte *self,
19ccae
@@ -156,12 +155,16 @@ virt_viewer_display_vte_adj_changed(VirtViewerDisplayVte *self,
19ccae
     gtk_widget_set_visible(self->priv->scroll,
19ccae
         gtk_adjustment_get_upper(adjustment) > gtk_adjustment_get_page_size(adjustment));
19ccae
 }
19ccae
+#endif
19ccae
 
19ccae
 GtkWidget *
19ccae
 virt_viewer_display_vte_new(VirtViewerSession *session, const char *name)
19ccae
 {
19ccae
     VirtViewerDisplayVte *self;
19ccae
-    GtkWidget *grid, *scroll = NULL, *vte;
19ccae
+    GtkWidget *grid, *vte;
19ccae
+#ifdef HAVE_VTE
19ccae
+    GtkWidget *scroll = NULL;
19ccae
+#endif
19ccae
 
19ccae
     self = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_VTE,
19ccae
                         "session", session,
19ccae
@@ -185,6 +188,8 @@ virt_viewer_display_vte_new(VirtViewerSession *session, const char *name)
19ccae
     grid = gtk_grid_new();
19ccae
 
19ccae
     gtk_container_add(GTK_CONTAINER(grid), vte);
19ccae
+
19ccae
+#ifdef HAVE_VTE
19ccae
     if (scroll) {
19ccae
         gtk_container_add(GTK_CONTAINER(grid), scroll);
19ccae
         gtk_widget_hide(scroll);
19ccae
@@ -192,6 +197,7 @@ virt_viewer_display_vte_new(VirtViewerSession *session, const char *name)
19ccae
                                           "changed", G_CALLBACK(virt_viewer_display_vte_adj_changed),
19ccae
                                           self, G_CONNECT_SWAPPED);
19ccae
     }
19ccae
+#endif
19ccae
 
19ccae
     gtk_container_add(GTK_CONTAINER(self), grid);
19ccae
 
19ccae
-- 
19ccae
2.28.0
19ccae