* [Qemu-devel] [PATCH] [VNC] Make sure to avoid sign extension when reading u{8, 16, 32}
@ 2006-08-02 1:51 Anthony Liguori
0 siblings, 0 replies; only message in thread
From: Anthony Liguori @ 2006-08-02 1:51 UTC (permalink / raw)
To: qemu-devel
[-- 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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-08-02 1:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-02 1:51 [Qemu-devel] [PATCH] [VNC] Make sure to avoid sign extension when reading u{8, 16, 32} Anthony Liguori
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).