mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
components/nvs: strlcpy is not available on Linux, replace with strncpy and terminate strings explicitly
This commit is contained in:
parent
3df4130eb7
commit
9ef827ae20
@ -18,7 +18,7 @@
|
||||
#include "crc.h"
|
||||
#endif
|
||||
#include <cstdio>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
@ -156,8 +156,8 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(item.key), sizeof(item.key) / 4, 0xffffffff);
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(item.data), sizeof(item.data) / 4, 0xffffffff);
|
||||
|
||||
strlcpy(item.key, key, Item::MAX_KEY_LENGTH + 1);
|
||||
|
||||
strncpy(item.key, key, sizeof(item.key) - 1);
|
||||
item.key[sizeof(item.key) - 1] = 0;
|
||||
|
||||
if (datatype != ItemType::SZ && datatype != ItemType::BLOB) {
|
||||
memcpy(item.data, data, dataSize);
|
||||
|
@ -161,7 +161,8 @@ esp_err_t Storage::createOrOpenNamespace(const char* nsName, bool canCreate, uin
|
||||
|
||||
NamespaceEntry* entry = new NamespaceEntry;
|
||||
entry->mIndex = ns;
|
||||
strlcpy(entry->mName, nsName, sizeof(entry->mName));
|
||||
strncpy(entry->mName, nsName, sizeof(entry->mName) - 1);
|
||||
entry->mName[sizeof(entry->mName) - 1] = 0;
|
||||
mNamespaces.push_back(entry);
|
||||
|
||||
} else {
|
||||
@ -250,4 +251,4 @@ void Storage::debugCheck()
|
||||
}
|
||||
#endif //ESP_PLATFORM
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
|
||||
$(OBJ_FILES): %.o: %.cpp
|
||||
|
||||
$(TEST_PROGRAM): $(OBJ_FILES)
|
||||
gcc $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES)
|
||||
g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES)
|
||||
|
||||
$(OUTPUT_DIR):
|
||||
mkdir -p $(OUTPUT_DIR)
|
||||
|
@ -19,7 +19,8 @@
|
||||
struct TestNode : public intrusive_list_node<TestNode> {
|
||||
TestNode(const char* name_ = "", int num_ = 0) : num(num_)
|
||||
{
|
||||
strlcpy(name, name_, sizeof(name));
|
||||
strncpy(name, name_, sizeof(name) - 1);
|
||||
name[sizeof(name) - 1] = 0;
|
||||
}
|
||||
char name[32];
|
||||
int num;
|
||||
|
@ -62,7 +62,7 @@ TEST_CASE("crc32 behaves as expected", "[nvs]")
|
||||
CHECK(crc32_1 != item2.calculateCrc32());
|
||||
|
||||
item2 = item1;
|
||||
strlcpy(item2.key, "foo", Item::MAX_KEY_LENGTH);
|
||||
strncpy(item2.key, "foo", Item::MAX_KEY_LENGTH);
|
||||
CHECK(crc32_1 != item2.calculateCrc32());
|
||||
}
|
||||
|
||||
@ -672,12 +672,12 @@ public:
|
||||
}
|
||||
if (err == ESP_ERR_NVS_REMOVE_FAILED) {
|
||||
written[index] = true;
|
||||
strlcpy(reinterpret_cast<char*>(values[index]), buf, strBufLen);
|
||||
strncpy(reinterpret_cast<char*>(values[index]), buf, strBufLen);
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
REQUIRE(err == ESP_OK);
|
||||
written[index] = true;
|
||||
strlcpy(reinterpret_cast<char*>(values[index]), buf, strBufLen);
|
||||
strncpy(reinterpret_cast<char*>(values[index]), buf, strBufLen);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user