Skip to content

Commit 9890731

Browse files
authored
Use only unsigned value for array access
GCC catches this bug. ``` ...\libraries\Adafruit_TinyUSB_Library\src\Adafruit_USBD_HID.cpp: Line 181 Char 22 In member function 'bool Adafruit_USBD_HID::keyboardPress(uint8_t, char)': warning: array subscript has type 'char' [-Wchar-subscripts] 181 | if (_ascii2keycode[ch][0]) | ^~ ...\libraries\Adafruit_TinyUSB_Library\src\Adafruit_USBD_HID.cpp: Line 183 Char 31 warning: array subscript has type 'char' [-Wchar-subscripts] 183 | keycode[0] = _ascii2keycode[ch][1]; | ^~ ```
1 parent 1ea58a1 commit 9890731

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Adafruit_USBD_HID.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ bool Adafruit_USBD_HID::keyboardReport(uint8_t report_id, uint8_t modifier,
177177
bool Adafruit_USBD_HID::keyboardPress(uint8_t report_id, char ch) {
178178
uint8_t keycode[6] = {0};
179179
uint8_t modifier = 0;
180+
uint8_t uch = (uint8_t)ch; // ensure no negative values used as index into array
180181

181-
if (_ascii2keycode[ch][0])
182+
if (_ascii2keycode[uch][0])
182183
modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
183-
keycode[0] = _ascii2keycode[ch][1];
184+
keycode[0] = _ascii2keycode[uch][1];
184185

185186
return tud_hid_keyboard_report(report_id, modifier, keycode);
186187
}

0 commit comments

Comments
 (0)