On Sat, Apr 2, 2016 at 8:00 PM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > On Sat, 2 Apr 2016, Navin P.S wrote: >>regs->hostpc[(wIndex & 0xff) - 1]; > > You're asking the question backwards. wIndex is allowed to be 0 > because the USB spec says so. You can't argue with that. > > You should be asking why we initialize status_reg and hostpc_reg as > above. >. Can i initialize them to NULL and only use them if wIndex is not zero and wIndex <= ports. I assign them goto error case statement. That would be a cleaner solution. >> This is only valid when we have regs->port_status and regs->hostpc and >> 1 more into the actual array but gcc catches this. > > No, it's always valid. The C spec might not agree with me, but the > kernel doesn't use standard C. It uses gcc, which is different from > the standard in quite a few ways. > If you had told me the size of port_status and hostpc is 65536 atleast i wouldn't have a problem because wIndex &0xff -1 when casted to a unit16_t would be 65535 when wIndex is 0. The 1 is treated as a signed integer constant and wIndex is an unsigned uint16_t. So the value of expression is -1 in this case. Please note i'm not talking about 0 sized arrays or 1 sized arrays inside struct. Can you please explain where gcc mentions this as valid ? https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions Here is some code. #include<stdio.h> #include<stdint.h> int main() { uint16_t x=0; uint16_t idx=(x&0xff)-1; int arr[70000]; arr[x-1]=0; // produces error because signed integer ( 4 byte and // and 2 bytes ) is signed ie -1 arr[idx]=0; // doesn't because it is // 65535 (2^16 - 1) when you cast -1 to uint16_t printf("%hu %d\n",idx,arr[idx]); return 0; } On another note not relevant to this thread I suspect ubsan to be wrong in another bug in atomic.h but i have to analyze that more in case of ip_idents_reserve. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html