From 0b976707d1f9ef8622ddb8dac5030ed9e5fa7236 Mon Sep 17 00:00:00 2001
From: Marcelo Tosatti <mtosatti@redhat.com>
Date: Tue, 11 May 2010 00:20:19 -0300
Subject: [PATCH 6/8] Fix SIGFPE for vnc display of width/height = 1

RH-Author: Marcelo Tosatti <mtosatti@redhat.com>
Message-id: <20100511002138.274857121@amt.cnet>
Patchwork-id: 9144
O-Subject: [RHEL6 qemu-kvm patch 10/16] Fix SIGFPE for vnc display of
	width/height = 1
Bugzilla:
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Bugzilla-related: 590922

commit 09e96924ec55eb0f1288ac44b271261055ed0657
From: Chris Webb <chris@arachsys.com>

Fix SIGFPE for vnc display of width/height = 1

During boot, the screen gets resized to height 1 and a mouse click at this
point will cause a division by zero when calculating the absolute pointer
position from the pixel (x, y). Return a click in the middle of the screen
instead in this case.

Signed-off-by: Chris Webb <chris@arachsys.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit cc39a92cbfc80c70d2b83708a4c9b309c3126ac3)
Bugzilla: 590922

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 vnc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/vnc.c b/vnc.c
index 584d298..ef450a6 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1470,8 +1470,10 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
         dz = 1;
 
     if (vs->absolute) {
-        kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1),
-                        y * 0x7FFF / (ds_get_height(vs->ds) - 1),
+        kbd_mouse_event(ds_get_width(vs->ds) > 1 ?
+                          x * 0x7FFF / (ds_get_width(vs->ds) - 1) : 0x4000,
+                        ds_get_height(vs->ds) > 1 ?
+                          y * 0x7FFF / (ds_get_height(vs->ds) - 1) : 0x4000,
                         dz, buttons);
     } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
         x -= 0x7FFF;
-- 
1.7.0.3

