Fix warning in symtab.c

Message ID 20210705174552.2200020-1-tom@tromey.com
State New
Headers show
Series
  • Fix warning in symtab.c
Related show

Commit Message

Tom Tromey July 5, 2021, 5:45 p.m.
The compiler gives this warning when building symtab.c:

../../binutils-gdb/gdb/symtab.c:4247:28: warning: ‘to_match’ may be used uninitialized in this function [-Wmaybe-uninitialized]

This patch fixes the warning by adding a gdb_assert_not_reached.
---
 gdb/symtab.c | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.26.3

Comments

H.J. Lu via Gdb-patches July 5, 2021, 5:48 p.m. | #1
On 2021-07-05 1:45 p.m., Tom Tromey wrote:
> The compiler gives this warning when building symtab.c:

> 

> ../../binutils-gdb/gdb/symtab.c:4247:28: warning: ‘to_match’ may be used uninitialized in this function [-Wmaybe-uninitialized]

> 

> This patch fixes the warning by adding a gdb_assert_not_reached.

> ---

>  gdb/symtab.c | 2 ++

>  1 file changed, 2 insertions(+)

> 

> diff --git a/gdb/symtab.c b/gdb/symtab.c

> index 6a9c3dce6af..fa3f42207ec 100644

> --- a/gdb/symtab.c

> +++ b/gdb/symtab.c

> @@ -4242,6 +4242,8 @@ info_sources_filter::matches (const char *fullname) const

>          case match_on::FULLNAME:

>            to_match = fullname;

>            break;

> +	default:

> +	  gdb_assert_not_reached ("bad m_match_type");

>          }

>  

>        if (m_c_regexp->exec (to_match, 0, NULL, 0) != 0)

> 


Thanks, that LGTM (and obvious-ish).

Simon
H.J. Lu via Gdb-patches July 8, 2021, 7:26 p.m. | #2
On 2021-07-05 1:48 p.m., Simon Marchi via Gdb-patches wrote:> On 2021-07-05 1:45 p.m., Tom Tromey wrote:
>> The compiler gives this warning when building symtab.c:

>>

>> ../../binutils-gdb/gdb/symtab.c:4247:28: warning: ‘to_match’ may be used uninitialized in this function [-Wmaybe-uninitialized]

>>

>> This patch fixes the warning by adding a gdb_assert_not_reached.

>> ---

>>  gdb/symtab.c | 2 ++

>>  1 file changed, 2 insertions(+)

>>

>> diff --git a/gdb/symtab.c b/gdb/symtab.c

>> index 6a9c3dce6af..fa3f42207ec 100644

>> --- a/gdb/symtab.c

>> +++ b/gdb/symtab.c

>> @@ -4242,6 +4242,8 @@ info_sources_filter::matches (const char *fullname) const

>>          case match_on::FULLNAME:

>>            to_match = fullname;

>>            break;

>> +	default:

>> +	  gdb_assert_not_reached ("bad m_match_type");

>>          }

>>  

>>        if (m_c_regexp->exec (to_match, 0, NULL, 0) != 0)

>>

> 

> Thanks, that LGTM (and obvious-ish).


Hi Tom,

When you push this, it would be good to push it to the gdb-11-branch as
well (with a ChangeLog entry).  See:

  https://sourceware.org/pipermail/gdb-patches/2021-July/180781.html

Thanks,

Simon
Joel Brobecker July 11, 2021, 2:36 p.m. | #3
> When you push this, it would be good to push it to the gdb-11-branch as

> well (with a ChangeLog entry).  See:

> 

>   https://sourceware.org/pipermail/gdb-patches/2021-July/180781.html


All taken care of :).

-- 
Joel

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 6a9c3dce6af..fa3f42207ec 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4242,6 +4242,8 @@  info_sources_filter::matches (const char *fullname) const
         case match_on::FULLNAME:
           to_match = fullname;
           break;
+	default:
+	  gdb_assert_not_reached ("bad m_match_type");
         }
 
       if (m_c_regexp->exec (to_match, 0, NULL, 0) != 0)