11/*
2- * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Unlicense OR CC0-1.0
55 */
@@ -54,32 +54,32 @@ static app_gap_cb_t m_dev_info;
5454static char * bda2str (esp_bd_addr_t bda , char * str , size_t size )
5555{
5656 if (bda == NULL || str == NULL || size < 18 ) {
57- return NULL ;
57+ return "" ;
5858 }
5959
6060 uint8_t * p = bda ;
61- sprintf (str , "%02x:%02x:%02x:%02x:%02x:%02x" ,
61+ snprintf (str , size , "%02x:%02x:%02x:%02x:%02x:%02x" ,
6262 p [0 ], p [1 ], p [2 ], p [3 ], p [4 ], p [5 ]);
6363 return str ;
6464}
6565
6666static char * uuid2str (esp_bt_uuid_t * uuid , char * str , size_t size )
6767{
6868 if (uuid == NULL || str == NULL ) {
69- return NULL ;
69+ return "" ;
7070 }
7171
7272 if (uuid -> len == 2 && size >= 5 ) {
73- sprintf (str , "%04x" , uuid -> uuid .uuid16 );
73+ snprintf (str , size , "%04x" , uuid -> uuid .uuid16 );
7474 } else if (uuid -> len == 4 && size >= 9 ) {
75- sprintf (str , "%08" PRIx32 , uuid -> uuid .uuid32 );
75+ snprintf (str , size , "%08" PRIx32 , uuid -> uuid .uuid32 );
7676 } else if (uuid -> len == 16 && size >= 37 ) {
7777 uint8_t * p = uuid -> uuid .uuid128 ;
78- sprintf (str , "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
78+ snprintf (str , size , "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
7979 p [15 ], p [14 ], p [13 ], p [12 ], p [11 ], p [10 ], p [9 ], p [8 ],
8080 p [7 ], p [6 ], p [5 ], p [4 ], p [3 ], p [2 ], p [1 ], p [0 ]);
8181 } else {
82- return NULL ;
82+ return "" ;
8383 }
8484
8585 return str ;
@@ -128,7 +128,7 @@ static void update_device_info(esp_bt_gap_cb_param_t *param)
128128 uint8_t eir_len = 0 ;
129129 esp_bt_gap_dev_prop_t * p ;
130130
131- ESP_LOGI (GAP_TAG , "Device found: %s" , bda2str (param -> disc_res .bda , bda_str , 18 ));
131+ ESP_LOGI (GAP_TAG , "Device found: %s" , bda2str (param -> disc_res .bda , bda_str , sizeof ( bda_str ) ));
132132 for (int i = 0 ; i < param -> disc_res .num_prop ; i ++ ) {
133133 p = param -> disc_res .prop + i ;
134134 switch (p -> type ) {
@@ -231,18 +231,19 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
231231 p_dev -> state == APP_GAP_STATE_SERVICE_DISCOVERING ) {
232232 p_dev -> state = APP_GAP_STATE_SERVICE_DISCOVER_COMPLETE ;
233233 if (param -> rmt_srvcs .stat == ESP_BT_STATUS_SUCCESS ) {
234- ESP_LOGI (GAP_TAG , "Services for device %s found" , bda2str (p_dev -> bda , bda_str , 18 ));
234+ ESP_LOGI (GAP_TAG , "Services for device %s found" , bda2str (p_dev -> bda , bda_str , sizeof ( bda_str ) ));
235235 for (int i = 0 ; i < param -> rmt_srvcs .num_uuids ; i ++ ) {
236236 esp_bt_uuid_t * u = param -> rmt_srvcs .uuid_list + i ;
237237 ESP_LOGI (GAP_TAG , "--%s" , uuid2str (u , uuid_str , 37 ));
238238 }
239239 } else {
240- ESP_LOGI (GAP_TAG , "Services for device %s not found" , bda2str (p_dev -> bda , bda_str , 18 ));
240+ ESP_LOGI (GAP_TAG , "Services for device %s not found" , bda2str (p_dev -> bda , bda_str , sizeof ( bda_str ) ));
241241 }
242242 }
243243 break ;
244244 }
245245 case ESP_BT_GAP_RMT_SRVC_REC_EVT :
246+ break ;
246247 default : {
247248 ESP_LOGI (GAP_TAG , "event: %d" , event );
248249 break ;
@@ -256,7 +257,7 @@ static void bt_app_gap_start_up(void)
256257 /* register GAP callback function */
257258 esp_bt_gap_register_callback (bt_app_gap_cb );
258259
259- char * dev_name = "ESP_GAP_INQRUIY " ;
260+ char * dev_name = "ESP_GAP_INQUIRY " ;
260261 esp_bt_gap_set_device_name (dev_name );
261262
262263 /* set discoverable and connectable mode, wait to be connected */
0 commit comments