Module: wine Branch: master Commit: 20a4842a896c950511919ba623a3d93c28e9a67d URL: http://source.winehq.org/git/wine.git/?a=commit;h=20a4842a896c950511919ba623...
Author: Aric Stewart aric@codeweavers.com Date: Mon Nov 7 13:44:33 2016 -0600
hid: Correct issues with getting packed values.
Signed-off-by: Aric Stewart aric@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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 4a0fa64..56bb91a 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; } }