We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4583 - PollAllValues appears to use an incorrect index for all axes above 0x18
Summary: PollAllValues appears to use an incorrect index for all axes above 0x18
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.1
Hardware: All Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.10
Depends on:
Blocks:
 
Reported: 2019-04-06 22:06 UTC by Noam Preil
Modified: 2019-06-08 21:41 UTC (History)
1 user (show)

See Also:


Attachments
Patch generated off of the GitHub mirror (1.99 KB, text/plain)
2019-04-06 22:06 UTC, Noam Preil
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Noam Preil 2019-04-06 22:06:02 UTC
Created attachment 3734 [details]
Patch generated off of the GitHub mirror

In src/joystick/linux/SDL_sysjoystick.c:

The ConfigJoystick function's axes detection starts with a for loop using an index i for Linux's axes names. When i gets to ABS_HAT0X, it's set to ABS_HAT3Y and a continue statement appears, to skip the hats. This makes sense, as SDL handles hats separately from axes.

However, in PollAllValues, *two* indices are used: a and b. Both start out the same, and remain so until the hats are reached. At that point, a becomes identical to the i from ConfigJoystick's loop, but b is equal to a - (ABS_HAT3Y - ABS_HAT0X), or a - 8.

While all the joystick->hwdata->abs_* structures in ConfigJoystick used i - which would here be a - as both the index and the ioctl argument, PollAllValues uses b for the structure index and a as the ioctl argument.

It would appear, however, that no joystick HAS such axes, and that the b index is entirely unnecessary.

I tested three separate joysticks, and while that was far from a complete listing, I was unable to find a joystick with an axis above 0x08.

This appears to be a bug that has remained unnoticed simply because no hardware is capable of triggering it.

It's also entirely possible that I missed something, and that it's supposed to be like this, but after spending two days trying to find something I decided to report it and hope I didn't regret it.

Thanks for your time.
Comment 1 Ryan C. Gordon 2019-05-18 18:48:54 UTC
Tagging a bunch of bugs with "target-2.0.10" so we have a clear list of things to address before a 2.0.10 release.

Please note that "addressing" one of these bugs might mean deciding to defer on it until after 2.0.10, or resolving it as WONTFIX, etc. This is just here to tell us we should look at it carefully, and soon.

If you have new information or feedback on this issue, this is a good time to add it to the conversation, as we're likely to be paying attention to this specific report in the next few days/weeks.

Thanks!

--ryan.
Comment 2 Sam Lantinga 2019-06-08 21:41:51 UTC
You're right, that looks like a bug. The index used in PollAllValues() should match the one used to initialize the structures in ConfigJoystick(). I think the latter function was updated at some point and PollAllValues() wasn't updated to match.

Your patch has been added, thanks!
https://hg.libsdl.org/SDL/rev/26634e392a7f