UltimateHackingKeyboard / firmware

Ultimate Hacking Keyboard firmware
Other
418 stars 65 forks source link

Try fix warning. #753

Closed kareltucek closed 7 months ago

kareltucek commented 7 months ago

Compiler throws:

/opt/firmware/right/src/buspal/bm_usb/usb_descriptor.c:60:37: warning: expression does not compute the number of elements in this array; element type is 'usb_device_interface_struct_t' {aka 'struct _usb_device_interface_struct'}, not 'usb_device_interfaces_struct_t' {aka 'struct _usb_device_interfaces_struct'}
[-Wsizeof-array-div]
   60 |     sizeof(g_hid_generic_interface) / sizeof(usb_device_interfaces_struct_t),
      |                                     ^
/opt/firmware/right/src/buspal/bm_usb/usb_descriptor.c:60:37: note: add parentheses around the second 'sizeof' to silence this warning
/opt/firmware/right/src/buspal/bm_usb/usb_descriptor.c:45:31: note: array 'g_hid_generic_interface' declared here
   45 | usb_device_interface_struct_t g_hid_generic_interface[] = { {
      |                               ^~~~~~~~~~~~~~~~~~~~~~~

Following fix seems to makes sense. UHK seems to work fine like this, but to tell the truth I am not entirely sure that the fix is correct, as I don't see much into the usb machinery.

mondalaci commented 7 months ago

@benedekkupper Please take a look and let us know if this fix is correct.

benedekkupper commented 7 months ago

Noone needs to look into the USB machinery, it's sufficient to look at the code. This line fixes the count field of usb_device_interfaces_struct_t, which should be set by the array size of what's set at the interface field. The interface has usb_device_interface_struct_t* type, so does g_hid_generic_interface. The fix is correct. (Whether this bug was patched somewhere else to make the whole system operational at the end is another question, one that I cannot answer so easily.)