This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Fix 8.2 regression in gdb.python/py-evthreads.exp w/ gdbserver (PR gdb/23379)


On 2018-08-25 10:52 a.m., Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> 	* python/py-threadevent.c (get_event_thread): Rename to ...
> Pedro> 	(py_get_event_thread): ... this, make extern, add 'ptid' parameter
> 
> I get this warning now:
> 
> ../../binutils-gdb/gdb/python/py-threadevent.c: In function ‘PyObject* py_get_event_thread(ptid_t)’:
> ../../binutils-gdb/gdb/python/py-threadevent.c:39:3: warning: ‘pythread’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> ... which seems legitimate to me:
> 
>   PyObject *pythread;
> 
>   if (non_stop)
>     {
>       thread_info *thread = find_thread_ptid (ptid);
>       if (thread != nullptr)
> 	pythread = (PyObject *) thread_to_thread_object (thread);
> // ... else pythread is uninitialized ...
>     }
> 
> pythread should be set to nullptr where I stuck the comment (or
> initialized to nullptr).
> 
> Tom
> 

Huh indeed, thanks for pointing it out.  I wonder why I don't get the warning with my gcc 8.2.0...

I pushed this patch to master and the 8.2 branch.

>From bbbbbceebc342d583057a11d88bae85f451cd904 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Sat, 25 Aug 2018 11:52:24 -0400
Subject: [PATCH] Initialize variable in py_get_event_thread

The pythread variable could be used without being initialized, fix it by
initializing it to nullptr.

gdb/ChangeLog:

	* python/py-threadevent.c (py_get_event_thread): Initialize
	pythread.
---
 gdb/ChangeLog               | 5 +++++
 gdb/python/py-threadevent.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 12dda6c541d9..9e3d6bc27acd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-25  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* python/py-threadevent.c (py_get_event_thread): Initialize
+	pythread.
+
 2018-08-24  Pedro Alves  <palves@redhat.com>

 	* python/py-bpevent.c (create_breakpoint_event_object): Use
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index a78f0a38310c..4f822b4ae09c 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -25,7 +25,7 @@
 PyObject *
 py_get_event_thread (ptid_t ptid)
 {
-  PyObject *pythread;
+  PyObject *pythread = nullptr;

   if (non_stop)
     {
@@ -36,7 +36,7 @@ py_get_event_thread (ptid_t ptid)
   else
     pythread = Py_None;

-  if (!pythread)
+  if (pythread == nullptr)
     {
       PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
       return NULL;
-- 
2.18.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]