[v2] elf.c: initialize struct stat

Message ID 1554705289-451606-1-git-send-email-mingli.yu@windriver.com
State New
Headers show
Series
  • [v2] elf.c: initialize struct stat
Related show

Commit Message

Yu, Mingli April 8, 2019, 6:34 a.m.
From: Mingli Yu <Mingli.Yu@windriver.com>


Initialize struct stat to fix the below
build failure when -Og included in compiler flag.
| ./../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c: In function 'elf_is_symlink':
| ../../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   return S_ISLNK (st.st_mode);

Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>

---
 libbacktrace/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.7.4

Comments

Jeff Law April 8, 2019, 2:21 p.m. | #1
On 4/8/19 12:34 AM, mingli.yu@windriver.com wrote:
> From: Mingli Yu <Mingli.Yu@windriver.com>

> 

> Initialize struct stat to fix the below

> build failure when -Og included in compiler flag.

> | ./../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c: In function 'elf_is_symlink':

> | ../../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]

>    return S_ISLNK (st.st_mode);

> 

> Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>

> ---

>  libbacktrace/elf.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

This is a false positive in -Wuninitialized that can be worked around by
compiling with -O2.  Please do that rather than compiling with -Og.

jeff
Yu, Mingli April 9, 2019, 1:52 a.m. | #2
On 2019年04月08日 22:21, Jeff Law wrote:
> On 4/8/19 12:34 AM, mingli.yu@windriver.com wrote:

>> From: Mingli Yu <Mingli.Yu@windriver.com>

>>

>> Initialize struct stat to fix the below

>> build failure when -Og included in compiler flag.

>> | ./../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c: In function 'elf_is_symlink':

>> | ../../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]

>>     return S_ISLNK (st.st_mode);

>>

>> Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>

>> ---

>>   libbacktrace/elf.c | 2 +-

>>   1 file changed, 1 insertion(+), 1 deletion(-)

> This is a false positive in -Wuninitialized that can be worked around by

> compiling with -O2.  Please do that rather than compiling with -Og.


Thanks Jeff for your respond!

Hi Khem,

If so, do we need to just to add some logic as DEBUG_OPTIMIZATION_append 
= " -Wno-error" for gcc-sanitizers to avoid -Og indicating the 
-Werror=maybe-uninitialized message?

Thanks,

>

> jeff

>
Khem Raj April 9, 2019, 2:07 a.m. | #3
On Mon, Apr 8, 2019 at 6:47 PM Yu, Mingli <mingli.yu@windriver.com> wrote:
>

>

>

> On 2019年04月08日 22:21, Jeff Law wrote:

> > On 4/8/19 12:34 AM, mingli.yu@windriver.com wrote:

> >> From: Mingli Yu <Mingli.Yu@windriver.com>

> >>

> >> Initialize struct stat to fix the below

> >> build failure when -Og included in compiler flag.

> >> | ./../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c: In function 'elf_is_symlink':

> >> | ../../../../../../../../../work-shared/gcc-8.3.0-r0/gcc-8.3.0/libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]

> >>     return S_ISLNK (st.st_mode);

> >>

> >> Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>

> >> ---

> >>   libbacktrace/elf.c | 2 +-

> >>   1 file changed, 1 insertion(+), 1 deletion(-)

> > This is a false positive in -Wuninitialized that can be worked around by

> > compiling with -O2.  Please do that rather than compiling with -Og.

>

> Thanks Jeff for your respond!

>

> Hi Khem,

>

> If so, do we need to just to add some logic as DEBUG_OPTIMIZATION_append

> = " -Wno-error" for gcc-sanitizers to avoid -Og indicating the

> -Werror=maybe-uninitialized message?

>


yeah that would be fine.

> Thanks,

>

> >

> > jeff

> >

Patch

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index f3988ec..4ba8826 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -765,7 +765,7 @@  elf_syminfo (struct backtrace_state *state, uintptr_t addr,
 static int
 elf_is_symlink (const char *filename)
 {
-  struct stat st;
+  struct stat st = {0};
 
   if (lstat (filename, &st) < 0)
     return 0;