This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix potential NULL pointer dereference
- From: Pedro Alves <palves at redhat dot com>
- To: Luis Machado <lgustavo at codesourcery dot com>, gdb-patches at sourceware dot org
- Date: Mon, 24 Oct 2016 23:26:01 +0100
- Subject: Re: [PATCH] Fix potential NULL pointer dereference
- Authentication-results: sourceware.org; auth=none
- References: <1477345938-32287-1-git-send-email-lgustavo@codesourcery.com>
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)
> }
> CATCH (err, RETURN_MASK_ERROR)
> {
> + 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?
Thanks,
Pedro Alves