This is the mail archive of the 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] Fix potential NULL pointer dereference

On 10/24/2016 05:39 PM, Luis Machado wrote:
On 10/24/2016 05:26 PM, Pedro Alves wrote:
On 10/24/2016 10:52 PM, Luis Machado wrote:

diff --git a/gdb/exec.c b/gdb/exec.c
index 67ecc63..5eeac44 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -221,13 +221,20 @@ exec_file_locate_attach (int pid, int
defer_bp_reset, int from_tty)
+      const char *msg;
       if (err.message != NULL)
-    warning ("%s", err.message);
+    {
+      warning ("%s", err.message);
+      msg = err.message;
+    }
+      else
+    msg = "";

This is overcomplicating a bit, IMO.

       prev_err = err;

       /* Save message so it doesn't get trashed by the catch below.  */
-      prev_err.message = xstrdup (err.message);
+      prev_err.message = xstrdup (msg);

I think this one liner:

 +      if (err.message != NULL)
          prev_err.message = xstrdup (err.message);

would have the same effect, since exception_print_same
handles NULL ex.message?

Pedro Alves

Fine by me. I'll push that change then.

Pushed as b5e1db87897cabfd9beb8b1bd49f7d965c0f2607 now.


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