|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
@@ -106,12 +106,20 @@ nimble_on_read(uint16_t conn_handle, |
106 | 106 | MODLOG_DFLT(DEBUG, " attr_handle=%d value=", attr->handle); |
107 | 107 | old_offset = s_read_data_len; |
108 | 108 | s_read_data_len += OS_MBUF_PKTLEN(attr->om); |
109 | | - s_read_data_val = realloc(s_read_data_val, s_read_data_len + 1); // 1 extra byte to store null char |
| 109 | + uint8_t *tmp = realloc(s_read_data_val, s_read_data_len + 1); |
| 110 | + if (tmp == NULL) { |
| 111 | + ESP_LOGE(TAG, "Failed to allocate memory for read data"); |
| 112 | + free(s_read_data_val); |
| 113 | + s_read_data_val = NULL; |
| 114 | + s_read_data_len = 0; |
| 115 | + return -1; |
| 116 | + } |
| 117 | + s_read_data_val = tmp; |
110 | 118 | ble_hs_mbuf_to_flat(attr->om, s_read_data_val + old_offset, OS_MBUF_PKTLEN(attr->om), NULL); |
111 | 119 | print_mbuf(attr->om); |
112 | 120 | return 0; |
113 | 121 | case BLE_HS_EDONE: |
114 | | - s_read_data_val[s_read_data_len] = 0; // to insure strings are ended with \0 */ |
| 122 | + s_read_data_val[s_read_data_len] = 0; // to ensure strings are ended with \0 */ |
115 | 123 | s_read_status = 0; |
116 | 124 | SEND_CB(); |
117 | 125 | return 0; |
@@ -289,7 +297,7 @@ desc_disced(uint16_t conn_handle, const struct ble_gatt_error *error, |
289 | 297 | } |
290 | 298 |
|
291 | 299 | /* this api does the following things : |
292 | | -** does service, characteristic and discriptor discovery and |
| 300 | +** does service, characteristic and descriptor discovery and |
293 | 301 | ** fills the hid device information accordingly in dev */ |
294 | 302 | static void read_device_services(esp_hidh_dev_t *dev) |
295 | 303 | { |
@@ -466,7 +474,7 @@ static void read_device_services(esp_hidh_dev_t *dev) |
466 | 474 | chr_end_handle, desc_disced, descr_result); |
467 | 475 | WAIT_CB(); |
468 | 476 | if (status != 0) { |
469 | | - ESP_LOGE(TAG, "failed to find discriptors for characteristic : %d", c); |
| 477 | + ESP_LOGE(TAG, "failed to find descriptors for characteristic : %d", c); |
470 | 478 | assert(status == 0); |
471 | 479 | } |
472 | 480 | dcount = dscs_discovered; |
|
0 commit comments