Fix strncpy truncating NUL terminating char

This fix handles the gcc's `-Wstringop-truncation` warning.

See:
<https://stackoverflow.com/questions/50198319/gcc-8-wstringop-truncation-what-is-the-good-practice>
This commit is contained in:
Slawomir Kwasniak
2021-03-22 21:14:25 +01:00
parent a12142064c
commit 514be7e23f
+2 -1
View File
@@ -954,7 +954,8 @@ s32_t spiffs_object_create(
oix_hdr.p_hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_USED);
oix_hdr.type = type;
oix_hdr.size = SPIFFS_UNDEFINED_LEN; // keep ones so we can update later without wasting this page
strncpy((char*)oix_hdr.name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
strncpy((char*)oix_hdr.name, (const char*)name, sizeof(oix_hdr.name) - 1);
((char*)oix_hdr.name)[sizeof(oix_hdr.name) - 1] = '\0';
#if SPIFFS_OBJ_META_LEN
if (meta) {
_SPIFFS_MEMCPY(oix_hdr.meta, meta, SPIFFS_OBJ_META_LEN);