Fix maybe-uninitialized warning in py-infthread.c
authorTom Tromey <tromey@adacore.com>
Mon, 28 Feb 2022 17:53:13 +0000 (10:53 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 28 Feb 2022 17:53:13 +0000 (10:53 -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.

gdb/python/py-infthread.c

index 66c3efdf6ccbf4343c86d37705051f5d48298c3a..c94d5b0ddab67940edc9469e6a16f4f84e5a016a 100644 (file)
@@ -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);