From 20a4842a896c950511919ba623a3d93c28e9a67d Mon Sep 17 00:00:00 2001 From: Aric Stewart Date: Mon, 7 Nov 2016 13:44:33 -0600 Subject: [PATCH] hid: Correct issues with getting packed values. Signed-off-by: Aric Stewart Signed-off-by: Alexandre Julliard --- dlls/hid/hidp.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dlls/hid/hidp.c b/dlls/hid/hidp.c index 4a0fa64df1a..56bb91aaa06 100644 --- a/dlls/hid/hidp.c +++ b/dlls/hid/hidp.c @@ -53,23 +53,26 @@ static NTSTATUS get_report_data(BYTE *report, INT reportLength, INT startBit, IN } else { - ULONG byte_index = (startBit + valueSize - 1) / 8; + ULONG byte_index = startBit / 8; ULONG data = 0; ULONG remainingBits = valueSize; + ULONG shift = 0; + ULONG begin_offset = startBit % 8; while (remainingBits) { - data <<= 8; - if (remainingBits >= 8) { - data |= report[byte_index]; - byte_index --; - remainingBits -= 8; + BYTE mask = 0xff << begin_offset; + data |= (report[byte_index] & mask) << shift; + byte_index ++; + remainingBits -= (8-begin_offset); + shift += (8-begin_offset); + begin_offset = 0; } else if (remainingBits > 0) { - BYTE mask = ~(0xff << (8-remainingBits)); - data |= report[byte_index] & mask; + BYTE mask = (0xff >> (8-remainingBits)) << begin_offset; + data |= (report[byte_index] & mask) << shift; remainingBits = 0; } }