summaryrefslogtreecommitdiff
path: root/src/class/hid
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2023-02-27 10:22:53 +0700
committerGitHub <[email protected]>2023-02-27 10:22:53 +0700
commit65ac519715ea0ecace08b183f2d8730d0450affd (patch)
tree11c48c98d3afea290e460deed624a07bac0607e7 /src/class/hid
parent73afca14eb589af84e932fdafbeeea8f8db1e771 (diff)
parente34aeb5cf69315d2d7711f0a1d040a28492d026d (diff)
Merge pull request #1852 from silvergasp/mem_s
fix: Replace device calls to memcpy with tu_memcpy_s
Diffstat (limited to 'src/class/hid')
-rw-r--r--src/class/hid/hid_device.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index ef44585f9..9240fe2ca 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -92,16 +92,12 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, u
// prepare data
if (report_id)
{
- len = tu_min16(len, CFG_TUD_HID_EP_BUFSIZE-1);
-
p_hid->epin_buf[0] = report_id;
- memcpy(p_hid->epin_buf+1, report, len);
+ TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf+1, CFG_TUD_HID_EP_BUFSIZE-1, report, len));
len++;
}else
{
- // If report id = 0, skip ID field
- len = tu_min16(len, CFG_TUD_HID_EP_BUFSIZE);
- memcpy(p_hid->epin_buf, report, len);
+ TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf, CFG_TUD_HID_EP_BUFSIZE, report, len));
}
return usbd_edpt_xfer(rhport, p_hid->ep_in, p_hid->epin_buf, len);
@@ -126,7 +122,7 @@ bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modi
if ( keycode )
{
- memcpy(report.keycode, keycode, 6);
+ memcpy(report.keycode, keycode, sizeof(report.keycode));
}else
{
tu_memclr(report.keycode, 6);
@@ -151,8 +147,7 @@ bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id,
}
bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id,
- int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons)
-{
+ int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) {
hid_gamepad_report_t report =
{
.x = x,
@@ -183,11 +178,12 @@ void hidd_reset(uint8_t rhport)
}
uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
-{
+ {
TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass, 0);
// len = interface + hid + n*endpoints
- uint16_t const drv_len = (uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
+ uint16_t const drv_len =
+ (uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
desc_itf->bNumEndpoints * sizeof(tusb_desc_endpoint_t));
TU_ASSERT(max_len >= drv_len, 0);