@@ -127,6 +127,7 @@ static uint8_t *GetDescHIDReport(int *len) {
127
127
128
128
if (report) {
129
129
free (report);
130
+ report = nullptr ;
130
131
}
131
132
132
133
if (__USBInstallKeyboard && __USBInstallMouse) {
@@ -136,21 +137,27 @@ static uint8_t *GetDescHIDReport(int *len) {
136
137
};
137
138
report_len = sizeof (desc_hid_report);
138
139
report = (uint8_t *)malloc (report_len);
139
- memcpy (report, desc_hid_report, report_len);
140
+ if (report) {
141
+ memcpy (report, desc_hid_report, report_len);
142
+ }
140
143
} else if (__USBInstallKeyboard && ! __USBInstallMouse) {
141
144
uint8_t desc_hid_report[] = {
142
145
TUD_HID_REPORT_DESC_KEYBOARD (HID_REPORT_ID (1 ))
143
146
};
144
147
report_len = sizeof (desc_hid_report);
145
148
report = (uint8_t *)malloc (report_len);
146
- memcpy (report, desc_hid_report, report_len);
149
+ if (report) {
150
+ memcpy (report, desc_hid_report, report_len);
151
+ }
147
152
} else { // if (!__USBInstallKeyboard && __USBInstallMouse) {
148
153
uint8_t desc_hid_report[] = {
149
154
TUD_HID_REPORT_DESC_MOUSE (HID_REPORT_ID (1 ))
150
155
};
151
156
report_len = sizeof (desc_hid_report);
152
157
report = (uint8_t *)malloc (report_len);
153
- memcpy (report, desc_hid_report, report_len);
158
+ if (report) {
159
+ memcpy (report, desc_hid_report, report_len);
160
+ }
154
161
}
155
162
156
163
if (len) {
@@ -205,20 +212,22 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
205
212
206
213
// Combine to one descriptor
207
214
usbd_desc_cfg = (uint8_t *)malloc (usbd_desc_len);
208
- bzero (usbd_desc_cfg, usbd_desc_len);
209
- uint8_t *ptr = usbd_desc_cfg;
210
- memcpy (ptr, tud_cfg_desc, sizeof (tud_cfg_desc));
211
- ptr += sizeof (tud_cfg_desc);
212
- if (__USBInstallSerial) {
213
- memcpy (ptr, cdc_desc, sizeof (cdc_desc));
214
- ptr += sizeof (cdc_desc);
215
- }
216
- if (hasHID) {
217
- memcpy (ptr, hid_desc, sizeof (hid_desc));
218
- ptr += sizeof (hid_desc);
219
- }
220
- if (__USBInstallMIDI) {
221
- memcpy (ptr, midi_desc, sizeof (midi_desc));
215
+ if (usbd_desc_cfg) {
216
+ bzero (usbd_desc_cfg, usbd_desc_len);
217
+ uint8_t *ptr = usbd_desc_cfg;
218
+ memcpy (ptr, tud_cfg_desc, sizeof (tud_cfg_desc));
219
+ ptr += sizeof (tud_cfg_desc);
220
+ if (__USBInstallSerial) {
221
+ memcpy (ptr, cdc_desc, sizeof (cdc_desc));
222
+ ptr += sizeof (cdc_desc);
223
+ }
224
+ if (hasHID) {
225
+ memcpy (ptr, hid_desc, sizeof (hid_desc));
226
+ ptr += sizeof (hid_desc);
227
+ }
228
+ if (__USBInstallMIDI) {
229
+ memcpy (ptr, midi_desc, sizeof (midi_desc));
230
+ }
222
231
}
223
232
}
224
233
return usbd_desc_cfg;
0 commit comments