aboutsummaryrefslogtreecommitdiff
path: root/gdb/mdebugread.c
diff options
context:
space:
mode:
authorEnze Li <enze.li@hotmail.com>2023-09-12 21:40:05 +0800
committerEnze Li <enze.li@hotmail.com>2023-09-12 21:43:06 +0800
commitd1722abe60ca7c330210aa97c8ec52ff98644206 (patch)
treee48e7209588f5e06e31567815beaaa25fe52a195 /gdb/mdebugread.c
parentaa240fbd480651bd72b3cebe7b5ea1cda204b7e9 (diff)
downloadgdb-d1722abe60ca7c330210aa97c8ec52ff98644206.zip
gdb-d1722abe60ca7c330210aa97c8ec52ff98644206.tar.gz
gdb-d1722abe60ca7c330210aa97c8ec52ff98644206.tar.bz2
gdb: Fix -Wuninitialized issue
I see the following warning when building GDB on FreeBSD/amd64 with Clang 14, ====================================================================== CXX mdebugread.o mdebugread.c:1069:3: error: variable 'f' is uninitialized when used here [-Werror,-Wuninitialized] f->set_loc_enumval (tsym.value); ^ mdebugread.c:836:17: note: initialize the variable 'f' to silence this warning struct field *f; ^ = nullptr ====================================================================== after digging a little, I realized that we can not simply do what Clang 14 says. The root cause of this issue is that we lost the initialization of the variable 'f' in this commit, commit 2774f2dad5f05e68771c07df6ab0fb23baa2118e Date: Thu Aug 31 09:37:44 2023 +0200 [gdb/symtab] Factor out type::{alloc_fields,copy_fields} we have made these modifications, --------------------------------------------------------------------- --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1034,9 +1034,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, t->set_code (type_code); t->set_length (sh->value); - t->set_num_fields (nfields); - f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field))); - t->set_fields (f); + t->alloc_fields (nfields, false); --------------------------------------------------------------------- The problem is that the variable 'f' is used in the second half of parse_symbol, that's why Clang complained. To fix this issue we need to ensure that the varibale 'f' is initialized. Calling the fields method is an obvious way to fix this issue. Tested on FreeBSD/amd64 by rebuilding. Approved-By: Tom de Vries <tdevries@suse.de>
Diffstat (limited to 'gdb/mdebugread.c')
-rw-r--r--gdb/mdebugread.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index ea3e15b..9cb30ce 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1035,6 +1035,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
t->set_code (type_code);
t->set_length (sh->value);
t->alloc_fields (nfields);
+ f = t->fields();
if (type_code == TYPE_CODE_ENUM)
{