[SLOF] [PATCH 2/4] romfs/tools: Silence GCC 8.1 compiler warning with FLASHFS_MAGIC

Thomas Huth thuth at redhat.com
Wed Jul 18 22:41:42 AEST 2018


GCC 8.1 introduce some new warnings which affect create_crc.c. One of
them is:

create_crc.c: In function ‘createHeaderImage’:
create_crc.c:110:2: warning: ‘strncpy’ output truncated before terminating nul
 copying 8 bytes from a string of the same length [-Wstringop-truncation]
  strncpy(uHeader.stHeader.magic, FLASHFS_MAGIC, 8);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Initialize the header struct statically here instead to silence the warning.

Suggested-by: Segher Boessenkool <segher at kernel.crashing.org>
Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 romfs/tools/create_crc.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c
index d33dfe4..ca24dfd 100644
--- a/romfs/tools/create_crc.c
+++ b/romfs/tools/create_crc.c
@@ -72,13 +72,15 @@ createHeaderImage(int notime)
 	char dastr[16] = { 0, };
 	unsigned long long da = 0;
 
-	struct stH stHeader;
+	struct stH stHeader = {
+		.magic = FLASHFS_MAGIC,
+		.platform_name = FLASHFS_PLATFORM_MAGIC,
+		.platform_revision = FLASHFS_PLATFORM_REVISION,
+		.ui64FileEnd = -1,
+	};
 
 	assert(sizeof(stHeader) == FLASHFS_HEADER_DATA_SIZE);
 
-	/* initialize Header */
-	memset(&stHeader, 0x00, FLASHFS_HEADER_DATA_SIZE);
-
 	/* read driver info */
 	if (NULL != (pcVersion = getenv("DRIVER_NAME"))) {
 		strncpy(stHeader.version, pcVersion, 16);
@@ -106,17 +108,6 @@ createHeaderImage(int notime)
 	}
 	memcpy(stHeader.date, &da, 8);
 
-	/* write Magic value into data stream */
-	strncpy(stHeader.magic, FLASHFS_MAGIC, 8);
-	/* write platform name into data stream */
-	strcpy(stHeader.platform_name, FLASHFS_PLATFORM_MAGIC);
-	/* write platform revision into data stream */
-	strcpy(stHeader.platform_revision, FLASHFS_PLATFORM_REVISION);
-
-
-	/* fill end of file info (8 bytes of FF) into data stream */
-	stHeader.ui64FileEnd = -1;
-
 	/* read address of next file and address of header date, both are 64 bit values */
 	ui64RomAddr = 0;
 	ui64DataAddr = 0;
-- 
1.8.3.1



More information about the SLOF mailing list