@@ -92,16 +92,12 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, u
9292 // prepare data
9393 if (report_id )
9494 {
95- len = tu_min16 (len , CFG_TUD_HID_EP_BUFSIZE - 1 );
96-
9795 p_hid -> epin_buf [0 ] = report_id ;
98- memcpy ( p_hid -> epin_buf + 1 , report , len );
96+ TU_VERIFY ( 0 == tu_memcpy_s ( p_hid -> epin_buf + 1 , CFG_TUD_HID_EP_BUFSIZE - 1 , report , len ) );
9997 len ++ ;
10098 }else
10199 {
102- // If report id = 0, skip ID field
103- len = tu_min16 (len , CFG_TUD_HID_EP_BUFSIZE );
104- memcpy (p_hid -> epin_buf , report , len );
100+ TU_VERIFY (0 == tu_memcpy_s (p_hid -> epin_buf , CFG_TUD_HID_EP_BUFSIZE , report , len ));
105101 }
106102
107103 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
126122
127123 if ( keycode )
128124 {
129- memcpy (report .keycode , keycode , 6 );
125+ memcpy (report .keycode , keycode , sizeof ( report . keycode ) );
130126 }else
131127 {
132128 tu_memclr (report .keycode , 6 );
@@ -151,8 +147,7 @@ bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id,
151147}
152148
153149bool tud_hid_n_gamepad_report (uint8_t instance , uint8_t report_id ,
154- int8_t x , int8_t y , int8_t z , int8_t rz , int8_t rx , int8_t ry , uint8_t hat , uint32_t buttons )
155- {
150+ int8_t x , int8_t y , int8_t z , int8_t rz , int8_t rx , int8_t ry , uint8_t hat , uint32_t buttons ) {
156151 hid_gamepad_report_t report =
157152 {
158153 .x = x ,
@@ -183,11 +178,12 @@ void hidd_reset(uint8_t rhport)
183178}
184179
185180uint16_t hidd_open (uint8_t rhport , tusb_desc_interface_t const * desc_itf , uint16_t max_len )
186- {
181+ {
187182 TU_VERIFY (TUSB_CLASS_HID == desc_itf -> bInterfaceClass , 0 );
188183
189184 // len = interface + hid + n*endpoints
190- uint16_t const drv_len = (uint16_t ) (sizeof (tusb_desc_interface_t ) + sizeof (tusb_hid_descriptor_hid_t ) +
185+ uint16_t const drv_len =
186+ (uint16_t ) (sizeof (tusb_desc_interface_t ) + sizeof (tusb_hid_descriptor_hid_t ) +
191187 desc_itf -> bNumEndpoints * sizeof (tusb_desc_endpoint_t ));
192188 TU_ASSERT (max_len >= drv_len , 0 );
193189
0 commit comments