diff --git a/tests/gtest/fake_platform.cpp b/tests/gtest/fake_platform.cpp index 4ef602680..5c43d00c8 100644 --- a/tests/gtest/fake_platform.cpp +++ b/tests/gtest/fake_platform.cpp @@ -225,7 +225,7 @@ otError FakePlatform::SettingsGet(uint16_t aKey, uint16_t aIndex, uint8_t *aValu return OT_ERROR_NOT_FOUND; } - if (aIndex > setting->second.size()) + if (aIndex >= setting->second.size()) { return OT_ERROR_NOT_FOUND; } @@ -280,7 +280,13 @@ otError FakePlatform::SettingsDelete(uint16_t aKey, int aIndex) return OT_ERROR_NOT_FOUND; } - if (static_cast(aIndex) >= setting->second.size()) + if (aIndex == -1) + { + mSettings.erase(setting); + return OT_ERROR_NONE; + } + + if (aIndex < 0 || static_cast(aIndex) >= setting->second.size()) { return OT_ERROR_NOT_FOUND; } diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index ae850d96d..f9c171a44 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -319,7 +319,7 @@ OT_TOOL_WEAK otError otPlatSettingsGet(otInstance *, uint16_t aKey, int aIndex, return OT_ERROR_NOT_FOUND; } - if (aIndex > setting->second.size()) + if (aIndex < 0 || static_cast(aIndex) >= setting->second.size()) { return OT_ERROR_NOT_FOUND; } @@ -373,7 +373,13 @@ OT_TOOL_WEAK otError otPlatSettingsDelete(otInstance *, uint16_t aKey, int aInde return OT_ERROR_NOT_FOUND; } - if (aIndex >= setting->second.size()) + if (aIndex == -1) + { + settings.erase(setting); + return OT_ERROR_NONE; + } + + if (aIndex < 0 || static_cast(aIndex) >= setting->second.size()) { return OT_ERROR_NOT_FOUND; }