From 514be7e23f57eb9b50a48b6585549c57f0e954ef Mon Sep 17 00:00:00 2001 From: Slawomir Kwasniak Date: Mon, 22 Mar 2021 21:14:25 +0100 Subject: [PATCH] Fix strncpy truncating NUL terminating char This fix handles the gcc's `-Wstringop-truncation` warning. See: --- src/spiffs_nucleus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/spiffs_nucleus.c b/src/spiffs_nucleus.c index 911447c..a33b7c9 100644 --- a/src/spiffs_nucleus.c +++ b/src/spiffs_nucleus.c @@ -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);