forked from espressif/esp-idf
nvs_flash: replace strncpy + manual null termination with strlcpy
Since libbsd is now a build dependency on Linux, strncpy can be replaced with the safer and less verbose strlcpy.
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#include "nvs_storage.hpp"
|
#include "nvs_storage.hpp"
|
||||||
|
#if __has_include(<bsd/string.h>)
|
||||||
|
// for strlcpy
|
||||||
|
#include <bsd/string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ESP_PLATFORM
|
#ifndef ESP_PLATFORM
|
||||||
// We need NO_DEBUG_STORAGE here since the integration tests on the host add some debug code.
|
// We need NO_DEBUG_STORAGE here since the integration tests on the host add some debug code.
|
||||||
@@ -755,11 +759,7 @@ void Storage::fillEntryInfo(Item &item, nvs_entry_info_t &info)
|
|||||||
|
|
||||||
for (auto &name : mNamespaces) {
|
for (auto &name : mNamespaces) {
|
||||||
if(item.nsIndex == name.mIndex) {
|
if(item.nsIndex == name.mIndex) {
|
||||||
#pragma GCC diagnostic push
|
strlcpy(info.namespace_name, name.mName, sizeof(info.namespace_name));
|
||||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
|
||||||
strncpy(info.namespace_name, name.mName, sizeof(info.namespace_name) - 1);
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
info.namespace_name[sizeof(info.namespace_name) -1] = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user