public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Fix maybe-uninitialized warning in py-infthread.c
@ 2022-02-28 17:54 Tom Tromey
  2022-02-28 17:59 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-02-28 17:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I got this warning from py-infthread.c using the Fedora 34 system GCC:

../../binutils-gdb/gdb/python/py-infthread.c:102:30: warning: ‘extra_info’ may be used uninitialized in this function [-Wmaybe-uninitialized]

I think this happens because GDB_PY_HANDLE_EXCEPTION expands to an
'if' whose condition is always true -- but GCC can't know this.  This
patch avoids the warning by adding a harmless initialization.
---
 gdb/python/py-infthread.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 66c3efdf6cc..c94d5b0ddab 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -87,7 +87,9 @@ thpy_get_details (PyObject *self, void *ignore)
 
   THPY_REQUIRE_VALID (thread_obj);
 
-  const char *extra_info;
+  /* GCC can't tell that extra_info will always be assigned after the
+     'catch', so initialize it.  */
+  const char *extra_info = nullptr;
   try
     {
       extra_info = target_extra_thread_info (thread_obj->thread);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pushed] Fix maybe-uninitialized warning in py-infthread.c
  2022-02-28 17:54 [pushed] Fix maybe-uninitialized warning in py-infthread.c Tom Tromey
@ 2022-02-28 17:59 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2022-02-28 17:59 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> [2022-02-28 10:54:38 -0700]:

> I got this warning from py-infthread.c using the Fedora 34 system GCC:
> 
> ../../binutils-gdb/gdb/python/py-infthread.c:102:30: warning: ‘extra_info’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> I think this happens because GDB_PY_HANDLE_EXCEPTION expands to an
> 'if' whose condition is always true -- but GCC can't know this.  This
> patch avoids the warning by adding a harmless initialization.

Thanks for fixing this.

Andrew


> ---
>  gdb/python/py-infthread.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
> index 66c3efdf6cc..c94d5b0ddab 100644
> --- a/gdb/python/py-infthread.c
> +++ b/gdb/python/py-infthread.c
> @@ -87,7 +87,9 @@ thpy_get_details (PyObject *self, void *ignore)
>  
>    THPY_REQUIRE_VALID (thread_obj);
>  
> -  const char *extra_info;
> +  /* GCC can't tell that extra_info will always be assigned after the
> +     'catch', so initialize it.  */
> +  const char *extra_info = nullptr;
>    try
>      {
>        extra_info = target_extra_thread_info (thread_obj->thread);
> -- 
> 2.31.1
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-28 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 17:54 [pushed] Fix maybe-uninitialized warning in py-infthread.c Tom Tromey
2022-02-28 17:59 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).