Created
April 21, 2021 16:49
-
-
Save bgklika/2c2ed7b5969748b0d90cf84213a6bee8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/amazon-freertos/vendors/espressif/boards/esp32/ports/wifi/iot_wifi.c b/src/amazon-freertos/vendors/espressif/boards/esp32/ports/wifi/iot_wifi.c | |
index 98d964e36..99bad7122 100644 | |
--- a/src/amazon-freertos/vendors/espressif/boards/esp32/ports/wifi/iot_wifi.c | |
+++ b/src/amazon-freertos/vendors/espressif/boards/esp32/ports/wifi/iot_wifi.c | |
@@ -1089,24 +1109,32 @@ WIFIReturnCode_t WIFI_NetworkDelete( uint16_t usIndex ) | |
xRet = prvInitRegistry( xNvsHandle ); | |
} | |
} | |
- if( xRet == ESP_OK && usIndex < xRegistry.usNumNetworks ) | |
+ if( xRet == ESP_OK ) | |
{ | |
- snprintf(cWifiKey, MAX_WIFI_KEY_WIDTH, "%d", xRegistry.usStorageIdx[ usIndex ]); | |
- xRet = nvs_erase_key( xNvsHandle, cWifiKey ); | |
- | |
- if( xRet == ESP_OK ) | |
+ if (usIndex < xRegistry.usNumNetworks) | |
{ | |
- for( usIdx = usIndex + 1; usIdx < xRegistry.usNumNetworks; usIdx++ ) | |
+ snprintf(cWifiKey, MAX_WIFI_KEY_WIDTH, "%d", xRegistry.usStorageIdx[ usIndex ]); | |
+ xRet = nvs_erase_key( xNvsHandle, cWifiKey ); | |
+ | |
+ if( xRet == ESP_OK ) | |
{ | |
- xRegistry.usStorageIdx[ usIdx - 1 ] = xRegistry.usStorageIdx[ usIdx ]; | |
+ for( usIdx = usIndex + 1; usIdx < xRegistry.usNumNetworks; usIdx++ ) | |
+ { | |
+ xRegistry.usStorageIdx[ usIdx - 1 ] = xRegistry.usStorageIdx[ usIdx ]; | |
+ } | |
+ xRegistry.usNumNetworks--; | |
+ xRet = nvs_set_blob( xNvsHandle, "registry", &xRegistry, sizeof( xRegistry ) ); | |
} | |
- xRegistry.usNumNetworks--; | |
- xRet = nvs_set_blob( xNvsHandle, "registry", &xRegistry, sizeof( xRegistry ) ); | |
- } | |
- if( xRet == ESP_OK ) | |
+ if( xRet == ESP_OK ) | |
+ { | |
+ xRet = nvs_commit( xNvsHandle ); | |
+ } | |
+ } | |
+ else | |
{ | |
- xRet = nvs_commit( xNvsHandle ); | |
+ ESP_LOGE(TAG, "%s: Attempt to delete by wrong index %u but only %u items exist", __func__, usIndex, xRegistry.usNumNetworks); | |
+ xRet = ESP_ERR_INVALID_ARG; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment