nandpart: fix strncpy compiler warning

More recent versions of GCC warns about the usage of strncpy in
nandpart.c: we actually only (need to) copy the stub string part of the
magic string, without the terminating NUL character. This is fine in
our particular case, but raises the compiler's eyebrows:
===================
nand-part.c: In function '_get_mbr':
nand-part.c:93:4: warning: 'strncpy' output truncated before terminating
                  nul copying 8 bytes from a string of the same length
                  [-Wstringop-truncation]
   93 |    strncpy((char *)mbr->magic, MBR_MAGIC, 8);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===================

Switch to the more fitting memcpy() here to avoid the warning.

Signed-off-by: Andre Przywara <osp@andrep.de>
Reported-by: slange-dev
This commit is contained in:
Andre Przywara 2021-12-15 23:04:14 +00:00
parent 02a865f5f8
commit 6a9bde9d34

View File

@ -90,7 +90,7 @@ static MBR *_get_mbr(int fd, int mbr_num, int force)
printf("check partition table copy %d: ", mbr_num);
printmbrheader(mbr);
if (force) {
strncpy((char *)mbr->magic, MBR_MAGIC, 8);
memcpy(mbr->magic, MBR_MAGIC, 8);
mbr->version = MBR_VERSION;
return mbr;
}