On Sun, 3 Apr 2016, Navin P.S wrote:
> On Sat, Apr 2, 2016 at 8:00 PM, Alan Stern <[email protected]> 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.
You can't use a NULL pointer! You have to set it to a non-NULL value
before you can dereference it.
> I assign them goto error case statement.
I don't understand that sentence.
> That would be a cleaner solution.
It would not be cleaner than leaving the code the way it is.
> >> 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
I don't see why you have a problem anyway. There's nothing wrong with
assigning a nonsense value to a pointer, as long as you don't try to
use it. For example, your compiler might not like this program, but
the program won't cause an error when you run it:
int a[5];
int main()
{
int *x = &a[-1];
return 0;
}
> 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
It's probably not mentioned in there.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html