hid: Correct issues with getting packed values.

Signed-off-by: Aric Stewart <aric@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Aric Stewart 2016-11-07 13:44:33 -06:00 committed by Alexandre Julliard
parent 477e7fdfc0
commit 20a4842a89
1 changed files with 11 additions and 8 deletions

View File

@ -53,23 +53,26 @@ static NTSTATUS get_report_data(BYTE *report, INT reportLength, INT startBit, IN
} }
else else
{ {
ULONG byte_index = (startBit + valueSize - 1) / 8; ULONG byte_index = startBit / 8;
ULONG data = 0; ULONG data = 0;
ULONG remainingBits = valueSize; ULONG remainingBits = valueSize;
ULONG shift = 0;
ULONG begin_offset = startBit % 8;
while (remainingBits) while (remainingBits)
{ {
data <<= 8;
if (remainingBits >= 8) if (remainingBits >= 8)
{ {
data |= report[byte_index]; BYTE mask = 0xff << begin_offset;
byte_index --; data |= (report[byte_index] & mask) << shift;
remainingBits -= 8; byte_index ++;
remainingBits -= (8-begin_offset);
shift += (8-begin_offset);
begin_offset = 0;
} }
else if (remainingBits > 0) else if (remainingBits > 0)
{ {
BYTE mask = ~(0xff << (8-remainingBits)); BYTE mask = (0xff >> (8-remainingBits)) << begin_offset;
data |= report[byte_index] & mask; data |= (report[byte_index] & mask) << shift;
remainingBits = 0; remainingBits = 0;
} }
} }