diff options
| author | hathach <[email protected]> | 2026-03-09 14:37:55 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-03-09 14:43:17 +0700 |
| commit | 3ca7ad1573e4931d430cc3b6412a7a31da6072c2 (patch) | |
| tree | d5e238eb678dacda6ae723c7adbd19c54f83f81e /src/host | |
| parent | 4c7bfc4dbec60fb12d542562fd3843005c24300b (diff) | |
fix(usbh): correct memcpy usage to ensure proper alignment with `offsetof` in device descriptor handling
Diffstat (limited to 'src/host')
| -rw-r--r-- | src/host/usbh.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c index 6574e7819..75df6bf60 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -433,7 +433,7 @@ bool tuh_descriptor_get_device_local(uint8_t daddr, tusb_desc_device_t* desc_dev desc_device->bLength = sizeof(tusb_desc_device_t); desc_device->bDescriptorType = TUSB_DESC_DEVICE; - memcpy(&desc_device->bcdUSB, &dev->desc_device, sizeof(dev->desc_device)); + memcpy((uint8_t*) desc_device + offsetof(tusb_desc_device_t, bcdUSB), &dev->desc_device, sizeof(desc_device_noheader_t)); return true; } @@ -1751,7 +1751,7 @@ static void process_enumeration(tuh_xfer_t *xfer) { // save the received device descriptor tusb_desc_device_t const *desc_device = (tusb_desc_device_t const *) _usbh_epbuf.ctrl; - memcpy(&dev->desc_device, &desc_device->bcdUSB, sizeof(dev->desc_device)); + memcpy(&dev->desc_device, (const uint8_t*) desc_device + offsetof(tusb_desc_device_t, bcdUSB), sizeof(desc_device_noheader_t)); tuh_enum_descriptor_device_cb(daddr, desc_device); // callback tuh_descriptor_get_string_langid(daddr, _usbh_epbuf.ctrl, 2, |
