Skip to content

tinyusb: Correct descriptor string length calculation#182

Merged
hathach merged 1 commit intoadafruit:masterfrom
kaysievers:tinyusb-descriptor-len
Nov 19, 2019
Merged

tinyusb: Correct descriptor string length calculation#182
hathach merged 1 commit intoadafruit:masterfrom
kaysievers:tinyusb-descriptor-len

Conversation

@kaysievers
Copy link

This fixes strcpy_uni16() to return the correct number of characters.
It wasn't visible in the host so far, because the strings have been NUL
terminated.

@kaysievers
Copy link
Author

This is a real bug which should be fixed. Could you please have a look? Thanks!

@ladyada
Copy link
Member

ladyada commented Nov 17, 2019

@hathach can take a look

int buflen = 0;

while (i < bufsize) {
while (s[i] > 0 && i < bufsize) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, though should the extra condition is s[i] != 0 if we are trying to find the null terminator ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I am used to char being unsigned. You are right, checking !=0 should be safer and work in any case.

Copy link
Member

@hathach hathach Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaysievers yeah, would you mind pushing the update so that we could merge and fix this :).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and pushed with the fix. Tested it and dumped the descriptor, looks like the string lengths are fine:

String Descriptor Table
--------------------------------
Index  LANGID  String
0x00   0x0000  0x0409 
Hex dump: 
0x04 0x03 0x09 0x04 

0x01   0x0409  "V2"
Hex dump: 
0x06 0x03 0x56 0x00 0x32 0x00 

0x02   0x0409  "pad"
Hex dump: 
0x08 0x03 0x70 0x00 0x61 0x00 0x64 0x00 

0x03   0x0409  "226B0C055333395336202020FF093B13"
Hex dump: 
0x42 0x03 0x32 0x00 0x32 0x00 0x36 0x00 0x42 0x00 
0x30 0x00 0x43 0x00 0x30 0x00 0x35 0x00 0x35 0x00 
0x33 0x00 0x33 0x00 0x33 0x00 0x33 0x00 0x39 0x00 
0x35 0x00 0x33 0x00 0x33 0x00 0x36 0x00 0x32 0x00 
0x30 0x00 0x32 0x00 0x30 0x00 0x32 0x00 0x30 0x00 
0x46 0x00 0x46 0x00 0x30 0x00 0x39 0x00 0x33 0x00 
0x42 0x00 0x31 0x00 0x33 0x00 

This fixes strcpy_uni16() to return the correct number of characters.
It wasn't visible in the host so far, because the strings have been NUL
terminated.
Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you very much for the PR. Btw, I am still in the middle of other works, and haven't got time to work on your multiple MIDI pr although I really like to support multiple MIDIs. Please give me a bit more time :)

@hathach hathach merged commit 5f68c65 into adafruit:master Nov 19, 2019
@kaysievers kaysievers deleted the tinyusb-descriptor-len branch November 19, 2019 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants