Skip to content

Commit ca17d62

Browse files
gdsportscmaglie
gdsports
authored andcommitted
Fix configuration descriptor length
A 16 bit length was being stored in a 32 bit int without initializing the most significant 16 bits.
1 parent 4294d36 commit ca17d62

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libraries/USBHost/examples/USB_desc/USB_desc.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ byte getconfdescr( byte addr, byte conf )
217217
byte rcode;
218218
byte descr_length;
219219
byte descr_type;
220-
unsigned int total_length;
220+
uint16_t total_length;
221221
rcode = usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
222222
LOBYTE( total_length ) = buf[ 2 ];
223223
HIBYTE( total_length ) = buf[ 3 ];
224-
if( total_length > 256 ) { //check if total length is larger than buffer
224+
if( total_length > sizeof(buf)) { //check if total length is larger than buffer
225225
printProgStr(Conf_Trunc_str);
226-
total_length = 256;
226+
total_length = sizeof(buf);
227227
}
228228
rcode = usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
229229
while( buf_ptr < buf + total_length ) { //parsing descriptors

0 commit comments

Comments
 (0)