Run-time check values before doing bad computation

This commit is contained in:
Marc-André Lureau 2012-07-03 23:12:39 +02:00
parent 560767b573
commit 02b326f80b
2 changed files with 10 additions and 1 deletions

View File

@ -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
*/

View File

@ -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);