[ipxe-devel] [PATCH 1/1] [efi] avoid stringop-truncation error in util/elf2efi.c

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Aug 23 20:12:22 UTC 2018


Avoid the following error with gcc 7.3:

In function ‘process_section’,
    inlined from ‘elf2pe.isra.4’ at util/elf2efi.c:914:25:
util/elf2efi.c:497:2: error: ‘strncpy’ specified bound 8 equals
destination size [-Werror=stringop-truncation]
  strncpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) );
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

The truncation to eight charactres is desired here, so we don't want this
warning to create an error.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 src/util/elf2efi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 6718df77..39e2bb79 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -494,7 +494,10 @@ static struct pe_section * process_section ( struct elf_file *elf,
 	memset ( new, 0, sizeof ( *new ) + section_filesz );
 
 	/* Fill in section header details */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
 	strncpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) );
+#pragma GCC diagnostic pop
 	new->hdr.Misc.VirtualSize = section_memsz;
 	new->hdr.VirtualAddress = shdr->sh_addr;
 	new->hdr.SizeOfRawData = section_filesz;
-- 
2.18.0




More information about the ipxe-devel mailing list