Skip to content

Commit

Permalink
Revert "wcmUSB: Correct bounds check of maximum button number"
Browse files Browse the repository at this point in the history
This fixed the wrong issue, the undefined behavior was caused by
(1 << btn) defaulting to int rather than unsigned int. See the follow-up
commit for a fix.

This reverts commit bf61b3e.
  • Loading branch information
whot authored and jigpu committed Dec 5, 2023
1 parent bf61b3e commit 73f66d4
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/wcmUSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ mod_buttons(WacomCommonPtr common, unsigned int buttons, unsigned int btn, Bool
{
unsigned int mask;

if (btn >= sizeof(int) * 8 - 1)
if (btn >= sizeof(int) * 8)
{
wcmLogCommonSafe(common, W_ERROR,
"%s: Invalid button number %u. Insufficient storage\n",
Expand Down Expand Up @@ -2085,15 +2085,14 @@ static int usbProbeKeys(WacomDevicePtr priv)
TEST_CASE(test_mod_buttons)
{
WacomCommonRec common = {0};
for (size_t i = 0; i < sizeof(int) * 8 - 1; i++)
for (size_t i = 0; i < sizeof(int) * 8; i++)
{
unsigned int buttons = mod_buttons(&common, 0, i, 1);
assert(buttons == (1u << i));
buttons = mod_buttons(&common, 0, i, 0);
assert(buttons == 0);
}

assert(mod_buttons(&common, 0, sizeof(int) * 8 - 1, 1) == 0);
assert(mod_buttons(&common, 0, sizeof(int) * 8, 1) == 0);
}

Expand Down

0 comments on commit 73f66d4

Please sign in to comment.