From 6a9bde9d3436d73660a60e34b352e7503f754074 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Wed, 15 Dec 2021 23:04:14 +0000 Subject: [PATCH 1/2] 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 Reported-by: slange-dev --- nand-part.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nand-part.c b/nand-part.c index a0d46c5..af2169d 100644 --- a/nand-part.c +++ b/nand-part.c @@ -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; } From fa80ab13cf9162037a17116ce0b9c2d9870891b2 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Wed, 15 Dec 2021 23:29:01 +0000 Subject: [PATCH 2/2] fit-image: Fix endianess conversion A helper function in fit_image.c was using our self defined portable endianess conversion function, but was not including our endian header. This lead to broken builds on some setups: ========================== fit_image.c: In function 'fdt_getprop_u32': fit_image.c:86:9: warning: implicit declaration of function 'be32toh' [-Wimplicit-function-declaration] 86 | return be32toh(*(uint32_t *)prop->data); | ^~~~~~~ /usr/bin/ld: /tmp/cczFroQN.o: in function `fdt_getprop_u32': fit_image.c:(.text+0x1e0): undefined reference to `be32toh' collect2: error: ld returned 1 exit status ========================== Fix this by using the libfdt provided endianess conversion function, and using an easier way to get the property on the way. Signed-off-by: Andre Przywara Reported-by: kaidokert --- fit_image.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fit_image.c b/fit_image.c index 899e868..fcf32f1 100644 --- a/fit_image.c +++ b/fit_image.c @@ -77,13 +77,13 @@ static int fit_parse_arch(const char *value) static uint32_t fdt_getprop_u32(const void *fdt, int node, const char *name) { - const struct fdt_property *prop; + const fdt32_t *val; - prop = fdt_get_property(fdt, node, name, NULL); - if (!prop) + val = fdt_getprop(fdt, node, name, NULL); + if (!val) return ~0U; - return be32toh(*(uint32_t *)prop->data); + return fdt32_to_cpu(*val); } static const char *fdt_getprop_str(const void *fdt, int node, const char *name)