From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] [VNC] Make sure to avoid sign extension when reading u{8, 16, 32}
Date: Tue, 01 Aug 2006 20:51:21 -0500 [thread overview]
Message-ID: <44D00519.2030209@codemonkey.ws> (raw)
[-- Attachment #1: Type: text/plain, Size: 200 bytes --]
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
[-- Attachment #2: vnc-sign-ext.diff --]
[-- Type: text/x-patch, Size: 1769 bytes --]
# HG changeset patch
# User Anthony Liguori <anthony@codemonkey.ws>
# 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)
reply other threads:[~2006-08-02 1:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44D00519.2030209@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).