From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G85uN-00037I-Lj for qemu-devel@nongnu.org; Tue, 01 Aug 2006 21:52:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G85uM-00036b-P2 for qemu-devel@nongnu.org; Tue, 01 Aug 2006 21:52:26 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G85uM-00036L-HO for qemu-devel@nongnu.org; Tue, 01 Aug 2006 21:52:26 -0400 Received: from [70.112.29.108] (helo=localhost.localdomain) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G85xN-0004Mt-2F for qemu-devel@nongnu.org; Tue, 01 Aug 2006 21:55:33 -0400 Received: from localhost ([127.0.0.1]) by localhost.localdomain with esmtp (Exim 4.60) (envelope-from ) id 1G85tM-0004Xc-DE for qemu-devel@nongnu.org; Tue, 01 Aug 2006 20:51:24 -0500 Message-ID: <44D00519.2030209@codemonkey.ws> Date: Tue, 01 Aug 2006 20:51:21 -0500 From: Anthony Liguori MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090805000100070506020806" Subject: [Qemu-devel] [PATCH] [VNC] Make sure to avoid sign extension when reading u{8, 16, 32} Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------090805000100070506020806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hopefully this will help with some of the keycode problems that have been reported. Please let me know if this helps for you. Thanks to Eduardo Felipe for spotting this. Regards, Anthony Liguori --------------090805000100070506020806 Content-Type: text/x-patch; name="vnc-sign-ext.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vnc-sign-ext.diff" # HG changeset patch # User Anthony Liguori # Date 1154483284 18000 # Node ID 7fd54fda0e694562d0f0574da3208f4f7c8e28ff # Parent b790da7061d1bde769ee2103faaff8f14ce6f489 Use unsigned types to avoid sign extension diff -r b790da7061d1 -r 7fd54fda0e69 vnc.c --- a/vnc.c Tue Aug 01 21:21:11 2006 +0000 +++ b/vnc.c Tue Aug 01 20:48:04 2006 -0500 @@ -622,7 +622,7 @@ static void vnc_write_u32(VncState *vs, static void vnc_write_u16(VncState *vs, uint16_t value) { - char buf[2]; + uint8_t buf[2]; buf[0] = (value >> 8) & 0xFF; buf[1] = value & 0xFF; @@ -643,24 +643,28 @@ static void vnc_flush(VncState *vs) static uint8_t read_u8(char *data, size_t offset) { - return data[offset]; + uint8_t *ptr = (uint8_t *)data; + return ptr[offset]; } static uint16_t read_u16(char *data, size_t offset) { - return ((data[offset] & 0xFF) << 8) | (data[offset + 1] & 0xFF); + uint8_t *ptr = (uint8_t *)data; + return ((ptr[offset] & 0xFF) << 8) | (ptr[offset + 1] & 0xFF); } static int32_t read_s32(char *data, size_t offset) { - return (int32_t)((data[offset] << 24) | (data[offset + 1] << 16) | - (data[offset + 2] << 8) | data[offset + 3]); + uint8_t *ptr = (uint8_t *)data; + return (int32_t)((ptr[offset] << 24) | (ptr[offset + 1] << 16) | + (ptr[offset + 2] << 8) | ptr[offset + 3]); } static uint32_t read_u32(char *data, size_t offset) { - return ((data[offset] << 24) | (data[offset + 1] << 16) | - (data[offset + 2] << 8) | data[offset + 3]); + uint8_t *ptr = (uint8_t *)data; + return ((ptr[offset] << 24) | (ptr[offset + 1] << 16) | + (ptr[offset + 2] << 8) | ptr[offset + 3]); } static void client_cut_text(VncState *vs, size_t len, char *text) --------------090805000100070506020806--