common: elf: use strdup_const for symmetry
PATCH 1/2 common: elf: use strdup_const for symmetry
The elf->filename is free'd by free_const, but it's always allocated with strdup. Change this to strdup_const to be able to avoid duplicating string literals.
--- common/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/elf.c +1 -1
@@ -315,7 +315,7 @@ static struct elf_image *elf_check_init(const char *filename) }close (fd); - elf->filename =strdup (filename); + elf->filename =strdup_const (filename);if (!elf->filename) { ret = -ENOMEM ; goto err_free_hdr_buf;
Signature · 1 line
2.47.3
PATCH 2/2 common: elf: use memcmp for fixed-size comparison
strncmp would only make sense if it were taking the size of buf as argument, but it's taking the size of ELFMAG instead, which is a fixed 4 bytes. It's thus effectively equal to memcmp, so switch to using that instead.
--- common/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/elf.c +1 -1
@@ -201,7 +201,7 @@ static int load_elf_image_segments(struct elf_image *elf)static int elf_check_image (struct elf_image *elf,void *buf) { -if (strncmp (buf,ELFMAG ,SELFMAG )) { +if (memcmp (buf,ELFMAG ,SELFMAG )) {pr_err ("ELF magic not found.\n" );return -EINVAL ; }
Signature · 1 line
2.47.3
Sascha Hauer
AppliedQuoted 5 lines · Ahmad Fatoum
The
elf->filenameis free'd byfree_const, but it's always allocated with strdup. Change this tostrdup_constto be able to avoid duplicating string literals.
Applied, thanks!
[1/2] common: elf: use strdup_const for symmetry
https://git.pengutronix.de/cgit/barebox/commit/?id=2e47b5900193 (link may not be stable)
[2/2] common: elf: use memcmp for fixed-size comparison
https://git.pengutronix.de/cgit/barebox/commit/?id=3dc2cad1a7e7 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>