Aaron Merey c06d0b
commit 43829fb8780ecbe9d17aaed22d3dfcb806cb5f45
Aaron Merey c06d0b
Author: Mark Wielaard <mark@klomp.org>
Aaron Merey c06d0b
Date:   Thu Oct 24 10:44:25 2024 +0200
Aaron Merey c06d0b
Aaron Merey c06d0b
    stacktrace: Init elf_fd in sysprof_init_dwfl
Aaron Merey c06d0b
    
Aaron Merey c06d0b
    When building with LTO gcc believes elf_fd can be used uninitialized:
Aaron Merey c06d0b
    
Aaron Merey c06d0b
    In function ‘sysprof_init_dwfl’,
Aaron Merey c06d0b
        inlined from ‘sysprof_unwind_cb’ at stacktrace.c:1235:16:
Aaron Merey c06d0b
    stacktrace.c:1087:7: error: ‘elf_fd’ may be used uninitialized [-Werror=maybe-uninitialized]
Aaron Merey c06d0b
     1087 |       close (elf_fd);
Aaron Merey c06d0b
          |       ^
Aaron Merey c06d0b
    
Aaron Merey c06d0b
    This code won't be reached because if find_procfile doesn't initialize
Aaron Merey c06d0b
    elf_fd, it will return an error. But help the compiler by initializing
Aaron Merey c06d0b
    elf_fd to -1.
Aaron Merey c06d0b
    
Aaron Merey c06d0b
            * src/stacktrace.c (sysprof_init_dwfl): Init elf_fd to -1.
Aaron Merey c06d0b
    
Aaron Merey c06d0b
    Signed-off-by: Mark Wielaard <mark@klomp.org>
Aaron Merey c06d0b
Aaron Merey c06d0b
diff --git a/src/stacktrace.c b/src/stacktrace.c
Aaron Merey c06d0b
index 438cb1dd0d38..b912ca5de502 100644
Aaron Merey c06d0b
--- a/src/stacktrace.c
Aaron Merey c06d0b
+++ b/src/stacktrace.c
Aaron Merey c06d0b
@@ -1033,7 +1033,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui,
Aaron Merey c06d0b
     }
Aaron Merey c06d0b
 
Aaron Merey c06d0b
   Elf *elf = NULL;
Aaron Merey c06d0b
-  int elf_fd;
Aaron Merey c06d0b
+  int elf_fd = -1;
Aaron Merey c06d0b
   err = find_procfile (dwfl, &pid, &elf, &elf_fd);
Aaron Merey c06d0b
   if (err < 0)
Aaron Merey c06d0b
     {