Kaynağa Gözat

add exception handling for iperf example's scan when no ap was found

dongyou 5 yıl önce
ebeveyn
işleme
7da388e52a
1 değiştirilmiş dosya ile 5 ekleme ve 0 silme
  1. 5 0
      examples/wifi/iperf/main/cmd_wifi.c

+ 5 - 0
examples/wifi/iperf/main/cmd_wifi.c

@@ -63,6 +63,11 @@ static void scan_done_handler(void* arg, esp_event_base_t event_base,
     wifi_ap_record_t *ap_list_buffer;
 
     esp_wifi_scan_get_ap_num(&sta_number);
+    if (!sta_number) {
+        ESP_LOGE(TAG, "No AP found");
+        return;
+    }
+
     ap_list_buffer = malloc(sta_number * sizeof(wifi_ap_record_t));
     if (ap_list_buffer == NULL) {
         ESP_LOGE(TAG, "Failed to malloc buffer to print scan results");