[PATCH 2/2] common: elf: use memcmp for fixed-size comparison
Ahmad Fatoum
a.fatoum at barebox.org
Mon Jan 5 00:33:38 PST 2026
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.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
common/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/elf.c b/common/elf.c
index e8126c9b64e7..18c541bf827e 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -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;
}
--
2.47.3
More information about the barebox
mailing list