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] Fix potential NULL pointer dereference


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


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