[virt-tools-list] [PATCH virt-viewer 07/19] Run-time check values before doing bad computation

Marc-André Lureau marcandre.lureau at gmail.com
Mon Jul 16 16:57:42 UTC 2012


---
 src/virt-viewer-display.c |    6 +++++-
 src/virt-viewer-window.c  |    5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
index 43ec45e..a954671 100644
--- a/src/virt-viewer-display.c
+++ b/src/virt-viewer-display.c
@@ -403,6 +403,10 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
     DEBUG_LOG("Allocated %dx%d", allocation->width, allocation->height);
     gtk_widget_set_allocation(widget, allocation);
 
+    if (priv->desktopWidth == 0 ||
+        priv->desktopHeight == 0)
+        goto end;
+
     desktopAspect = (double)priv->desktopWidth / (double)priv->desktopHeight;
 
     if (child && gtk_widget_get_visible(child)) {
@@ -427,7 +431,7 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
         gtk_widget_size_allocate(child, &child_allocation);
     }
 
-
+end:
     /* This unsets the size request, so that the user can
      * manually resize the window smaller again
      */
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index c873ebc..4887e28 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -433,6 +433,11 @@ virt_viewer_window_resize(VirtViewerWindow *self)
                                     (screen, gtk_widget_get_window(priv->window)),
                                     &fullscreen);
 
+    g_return_if_fail(fullscreen.height > 128);
+    g_return_if_fail(fullscreen.width > 128);
+    g_return_if_fail(desktopWidth > 0);
+    g_return_if_fail(desktopHeight > 0);
+
     desktopAspect = (double)desktopWidth / (double)desktopHeight;
     screenAspect = (double)(fullscreen.width - 128) / (double)(fullscreen.height - 128);
 
-- 
1.7.10.4




More information about the virt-tools-list mailing list