@@ -53,32 +53,32 @@ static app_gap_cb_t m_dev_info;
5353static char * bda2str (esp_bd_addr_t bda , char * str , size_t size )
5454{
5555 if (bda == NULL || str == NULL || size < 18 ) {
56- return NULL ;
56+ return "" ;
5757 }
5858
5959 uint8_t * p = bda ;
60- sprintf (str , "%02x:%02x:%02x:%02x:%02x:%02x" ,
61- p [0 ], p [1 ], p [2 ], p [3 ], p [4 ], p [5 ]);
60+ snprintf (str , size , "%02x:%02x:%02x:%02x:%02x:%02x" ,
61+ p [0 ], p [1 ], p [2 ], p [3 ], p [4 ], p [5 ]);
6262 return str ;
6363}
6464
6565static char * uuid2str (esp_bt_uuid_t * uuid , char * str , size_t size )
6666{
6767 if (uuid == NULL || str == NULL ) {
68- return NULL ;
68+ return "" ;
6969 }
7070
7171 if (uuid -> len == 2 && size >= 5 ) {
72- sprintf (str , "%04x" , uuid -> uuid .uuid16 );
72+ snprintf (str , size , "%04x" , uuid -> uuid .uuid16 );
7373 } else if (uuid -> len == 4 && size >= 9 ) {
74- sprintf (str , "%08" PRIx32 , uuid -> uuid .uuid32 );
74+ snprintf (str , size , "%08" PRIx32 , uuid -> uuid .uuid32 );
7575 } else if (uuid -> len == 16 && size >= 37 ) {
7676 uint8_t * p = uuid -> uuid .uuid128 ;
77- sprintf (str , "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
78- p [15 ], p [14 ], p [13 ], p [12 ], p [11 ], p [10 ], p [9 ], p [8 ],
79- p [7 ], p [6 ], p [5 ], p [4 ], p [3 ], p [2 ], p [1 ], p [0 ]);
77+ snprintf (str , size , "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
78+ p [15 ], p [14 ], p [13 ], p [12 ], p [11 ], p [10 ], p [9 ], p [8 ],
79+ p [7 ], p [6 ], p [5 ], p [4 ], p [3 ], p [2 ], p [1 ], p [0 ]);
8080 } else {
81- return NULL ;
81+ return "" ;
8282 }
8383
8484 return str ;
@@ -127,7 +127,7 @@ static void update_device_info(esp_bt_gap_cb_param_t *param)
127127 uint8_t eir_len = 0 ;
128128 esp_bt_gap_dev_prop_t * p ;
129129
130- ESP_LOGI (GAP_TAG , "Device found: %s" , bda2str (param -> disc_res .bda , bda_str , 18 ));
130+ ESP_LOGI (GAP_TAG , "Device found: %s" , bda2str (param -> disc_res .bda , bda_str , sizeof ( bda_str ) ));
131131 for (int i = 0 ; i < param -> disc_res .num_prop ; i ++ ) {
132132 p = param -> disc_res .prop + i ;
133133 switch (p -> type ) {
@@ -230,18 +230,19 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
230230 p_dev -> state == APP_GAP_STATE_SERVICE_DISCOVERING ) {
231231 p_dev -> state = APP_GAP_STATE_SERVICE_DISCOVER_COMPLETE ;
232232 if (param -> rmt_srvcs .stat == ESP_BT_STATUS_SUCCESS ) {
233- ESP_LOGI (GAP_TAG , "Services for device %s found" , bda2str (p_dev -> bda , bda_str , 18 ));
233+ ESP_LOGI (GAP_TAG , "Services for device %s found" , bda2str (p_dev -> bda , bda_str , sizeof ( bda_str ) ));
234234 for (int i = 0 ; i < param -> rmt_srvcs .num_uuids ; i ++ ) {
235235 esp_bt_uuid_t * u = param -> rmt_srvcs .uuid_list + i ;
236236 ESP_LOGI (GAP_TAG , "--%s" , uuid2str (u , uuid_str , 37 ));
237237 }
238238 } else {
239- ESP_LOGI (GAP_TAG , "Services for device %s not found" , bda2str (p_dev -> bda , bda_str , 18 ));
239+ ESP_LOGI (GAP_TAG , "Services for device %s not found" , bda2str (p_dev -> bda , bda_str , sizeof ( bda_str ) ));
240240 }
241241 }
242242 break ;
243243 }
244244 case ESP_BT_GAP_RMT_SRVC_REC_EVT :
245+ break ;
245246 default : {
246247 ESP_LOGI (GAP_TAG , "event: %d" , event );
247248 break ;
@@ -255,7 +256,7 @@ static void bt_app_gap_start_up(void)
255256 /* register GAP callback function */
256257 esp_bt_gap_register_callback (bt_app_gap_cb );
257258
258- char * dev_name = "ESP_GAP_INQRUIY " ;
259+ char * dev_name = "ESP_GAP_INQUIRY " ;
259260 esp_bt_gap_set_device_name (dev_name );
260261
261262 /* set discoverable and connectable mode, wait to be connected */
0 commit comments