]> granicus.if.org Git - esp-idf/commitdiff
component/bt: fix nvs_get_str_or_blob length output error
authorbaohongde <baohongde@espressif.com>
Wed, 30 Aug 2017 10:01:24 +0000 (18:01 +0800)
committerbaohongde <baohongde@espressif.com>
Fri, 8 Sep 2017 04:02:35 +0000 (12:02 +0800)
components/nvs_flash/src/nvs_api.cpp
components/nvs_flash/test_nvs_host/test_nvs.cpp

index 57759ecd83798fda1280f998e70c9076cdad0408..9209657935186a5ab95f807cc365a99b5570a5ab 100644 (file)
@@ -400,7 +400,10 @@ static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, cons
     } else if (*length < dataSize) {
         *length = dataSize;
         return ESP_ERR_NVS_INVALID_LENGTH;
+    } else if (*length > dataSize) {
+       *length = dataSize;
     }
+    
 
     return entry.mStoragePtr->readItem(entry.mNsIndex, type, key, out_value, dataSize);
 }
index 5a35c11f4a12ad094a6e8c90f5248baab449b5c8..f419256cf334b9b8c7db3cd0f025c96e7cd53bce 100644 (file)
@@ -530,6 +530,10 @@ TEST_CASE("nvs api tests", "[nvs]")
     TEST_ESP_ERR(ESP_ERR_NVS_INVALID_LENGTH, nvs_get_str(handle_2, "key", buf, &buf_len_short));
     CHECK(buf_len_short == buf_len);
     
+    size_t buf_len_long = buf_len + 1;
+    TEST_ESP_OK(nvs_get_str(handle_2, "key", buf, &buf_len_long));
+    CHECK(buf_len_long == buf_len);
+
     TEST_ESP_OK(nvs_get_str(handle_2, "key", buf, &buf_len));
 
     CHECK(0 == strcmp(buf, str));