Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect multiple-count report field sizing #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schmidtsamuelw
Copy link

When enumerating a device's report fields, the resulting HIDInputReportItem is instantiated with a count and the size of an individual field. The total size of the item is the field size times the number of fields associated with this item, but HIDInputReport::push_back(), which is used to give instantiated report items their offset in the report's buffer, uses only the individual field's size.

The effect of this is that the offset for every HIDInputReportItem is incorrect (too low) after the first item that has a count greater than one. This PR is a simple fix to give HIDInputReportItem a public member to provide its total size to HIDInputReport so that correct offsets can be calculated.

@schmidtsamuelw schmidtsamuelw force-pushed the fix-multiple-count-reports branch from b56008a to b36087b Compare November 24, 2024 07:59
- Add `HIDInputReportItem::get_total_size()`, the item's size times
its count
- Use `HIDInputReportItem::get_total_size()` to calculate the correct
item offset in `HIDInputReport::push_back`

Offsets for `HIDInputReportItem` instances within a report are
calculated using the size of the field, but the message will contain
N fields of the given size. As a result, multiple-count fields give
every following `HIDInputReportItem` an incorrect offset when parsing
HID reports. In addition, the report's calculated total size is
incorrect, which would cause issues with any code that might rely on its
size in the future.

Introducing a member to provide the correct total size allows correct
calculation of a report's size.
@schmidtsamuelw schmidtsamuelw force-pushed the fix-multiple-count-reports branch from b36087b to 9b64375 Compare November 24, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant