From: Mark Wielaard Date: Thu, 24 Oct 2024 09:06:08 +0000 (+0200) Subject: stacktrace: Init elf_fd in sysprof_init_dwfl X-Git-Tag: elfutils-0.193~80 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dce324303198545e1c5484d912e5f259b1d4953d;p=thirdparty%2Felfutils.git stacktrace: Init elf_fd in sysprof_init_dwfl When building with LTO gcc believes elf_fd can be used uninitialized: In function ‘sysprof_init_dwfl’, inlined from ‘sysprof_unwind_cb’ at stacktrace.c:1235:16: stacktrace.c:1087:7: error: ‘elf_fd’ may be used uninitialized [-Werror=maybe-uninitialized] 1087 | close (elf_fd); | ^ This code won't be reached because if find_procfile doesn't initialize elf_fd, it will return an error. But help the compiler by initializing elf_fd to -1. * src/stacktrace.c (sysprof_init_dwfl): Init elf_fd to -1. Signed-off-by: Mark Wielaard --- diff --git a/src/stacktrace.c b/src/stacktrace.c index 438cb1dd..b912ca5d 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -1033,7 +1033,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui, } Elf *elf = NULL; - int elf_fd; + int elf_fd = -1; err = find_procfile (dwfl, &pid, &elf, &elf_fd); if (err < 0) {