Page 1 of 1

Char signedness bug in usbGenericSetInterrupt() [fixed]

Posted: Thu Nov 14, 2013 10:03 pm
by blargg

Code: Select all

static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus)
{
uchar   *p;
char    i;

[...]
    i = len;
    do{                         /* if len == 0, we still copy 1 byte, but that's no problem */
        *p++ = *data++;
    }while(--i > 0);            /* loop control at the end is 2 bytes shorter than at beginning */
[...]


It sure seems it's assuming that char is signed. It's common to use -funsigned-char to avoid unnecessary sign-extension, which would apparently break the above code. There is an schar in usbdrv.h:

Code: Select all

#ifndef schar
#define schar   signed char
#endif


so it doesn't seem they want to rely on char being signed.

Re: V-USB assumes that char is signed?!?

Posted: Thu Nov 14, 2013 10:16 pm
by christian
Please check out the current head on the master branch on github:

https://github.com/obdev/v-usb

Re: V-USB assumes that char is signed?!?

Posted: Thu Nov 14, 2013 10:24 pm
by blargg
OK, so it does not assume that char is signed, and what I found today was a bug and happened to be fixed two days ago. Hah.

Re: Char signedness bug in usbGenericSetInterrupt() [fixed]

Posted: Thu Nov 14, 2013 10:34 pm
by christian
It has been fixed months ago, but I forgot to commit and push it. The commit message is also a bit confusing since I did not remember what that particular fix was good for.