mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
bugfix (nvs): fixed wrong pointer check
This commit is contained in:
committed by
Jakob Hasse
parent
257d95fc22
commit
c8eb02bb39
@ -1,16 +1,8 @@
|
|||||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
/*
|
||||||
//
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
// you may not use this file except in compliance with the License.
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
#include "nvs_partition_manager.hpp"
|
#include "nvs_partition_manager.hpp"
|
||||||
#include "nvs_partition_lookup.hpp"
|
#include "nvs_partition_lookup.hpp"
|
||||||
@ -188,6 +180,10 @@ esp_err_t NVSPartitionManager::open_handle(const char *part_name,
|
|||||||
uint8_t nsIndex;
|
uint8_t nsIndex;
|
||||||
Storage* sHandle;
|
Storage* sHandle;
|
||||||
|
|
||||||
|
if (handle == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
if (nvs_storage_list.empty()) {
|
if (nvs_storage_list.empty()) {
|
||||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
@ -202,14 +198,14 @@ esp_err_t NVSPartitionManager::open_handle(const char *part_name,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = new (std::nothrow) NVSHandleSimple(open_mode==NVS_READONLY, nsIndex, sHandle);
|
NVSHandleSimple* new_handle = new (std::nothrow) NVSHandleSimple(open_mode==NVS_READONLY, nsIndex, sHandle);
|
||||||
|
if (new_handle == nullptr) {
|
||||||
if (handle == nullptr) {
|
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
nvs_handles.push_back(*handle);
|
nvs_handles.push_back(new_handle);
|
||||||
|
|
||||||
|
*handle = new_handle;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
/*
|
||||||
//
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
// you may not use this file except in compliance with the License.
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -70,6 +62,21 @@ TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]"
|
|||||||
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(part_1.get_partition_name()) == ESP_OK);
|
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(part_1.get_partition_name()) == ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Partition manager open fails on null handle", "[partition_mgr]")
|
||||||
|
{
|
||||||
|
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||||
|
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
|
||||||
|
PartitionEmulationFixture f(0, 10, "test");
|
||||||
|
|
||||||
|
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
|
||||||
|
== ESP_OK);
|
||||||
|
|
||||||
|
CHECK(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, nullptr)
|
||||||
|
== ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
|
NVSPartitionManager::get_instance()->deinit_partition("test");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Partition manager invalidates handle on partition de-init", "[partition_mgr]")
|
TEST_CASE("Partition manager invalidates handle on partition de-init", "[partition_mgr]")
|
||||||
{
|
{
|
||||||
const uint32_t NVS_FLASH_SECTOR = 6;
|
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||||
|
Reference in New Issue
Block a user