Skip to content

Commit e124cf3

Browse files
committed
Coverity CID 468156
Coverity is complaining about 32-bits being truncated to 16-bits. Make the data conversion to unsigned short explicit.
1 parent a9fc757 commit e124cf3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

common/scancode.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -367,19 +367,15 @@ scancode_to_index(unsigned short scancode)
367367
unsigned short
368368
scancode_from_index(int index)
369369
{
370-
index &= 0xff;
371-
unsigned short result;
372-
if (index == SCANCODE_INDEX_PAUSE_KEY)
370+
unsigned short result = index & 0xff;
371+
372+
if (result == SCANCODE_INDEX_PAUSE_KEY)
373373
{
374374
result = SCANCODE_PAUSE_KEY;
375375
}
376-
else if (index < 0x80)
377-
{
378-
result = index;
379-
}
380-
else
376+
else if ((result & 0x80) != 0)
381377
{
382-
result = (index & 0x7f) | 0x100;
378+
result ^= 0x180; // Clear bit 7, set bit 8
383379
}
384380
return result;
385381
}

0 commit comments

Comments
 (0)