Silence GCC "uninitialized" warning on minsyms.c:lookup_minimal_symbol_by_pc_section

Message ID 20180618202634.10452-1-sergiodj@redhat.com
State New, archived
Headers

Commit Message

Sergio Durigan Junior June 18, 2018, 8:26 p.m. UTC
  Commit 20944a6e20324cd897bf6c4c5fd20ef7224dacaa ("Fix stepping past
GNU ifunc resolvers (introduce lookup_msym_prefer)") introduced a new
way to determine the 'want_type' variable on
minsyms.c:lookup_minimal_symbol_by_pc_section.  Because the
'lookup_msym_prefer' has a default value, we know that 'want_type'
will always be initialized.  However, GCC is complaining that the
variable can be used uninitialized in the function:

  ../../gdb/minsyms.c: In function 'bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR, obj_section*, lookup_msym_prefer)':
  ../../gdb/minsyms.c:825:40: warning: 'want_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
	   && MSYMBOL_TYPE (&msymbol[hi]) != want_type

(This is with gcc-8.1.1-1.fc29.x86_64).

This patch fixes it by initializing 'want_type' with 'mst_text', which
is the same default value that is passed in the 'lookup_msym_prefer'
variable.

Even though this can be considered an obvious patch, I'm sending it
for approval.

gdb/ChangeLog:
2018-06-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* minsyms.c (lookup_minimal_symbol_by_pc_section): Initialize
	'want_type' to silence GCC warning.
---
 gdb/ChangeLog | 5 +++++
 gdb/minsyms.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4fc6cf5446..5cf9da8e56 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-06-18  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* minsyms.c (lookup_minimal_symbol_by_pc_section): Initialize
+	'want_type' to silence GCC warning.
+
 2018-06-18  Tom Tromey  <tom@tromey.com>
 
 	* solib-aix.c (solib_aix_get_section_offsets): Return
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 4882e58ee4..c9d89dc171 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -683,7 +683,7 @@  lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
   struct minimal_symbol *best_symbol = NULL;
   struct objfile *best_objfile = NULL;
   struct bound_minimal_symbol result;
-  enum minimal_symbol_type want_type;
+  enum minimal_symbol_type want_type = mst_text;
 
   if (section == NULL)
     {