Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Tom Tromey <tom@tromey.com>, <gdb-patches@sourceware.org>
Subject: Re: [RFA v3] Return gdb::optional<std::string> from target_fileio_readlink
Date: Wed, 07 Mar 2018 20:37:00 -0000	[thread overview]
Message-ID: <e96f8f08-4fe6-382c-4d44-7622eb824c70@ericsson.com> (raw)
In-Reply-To: <20180221213741.19409-1-tom@tromey.com>

On 2018-02-21 04:37 PM, Tom Tromey wrote:
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -11713,7 +11713,7 @@ remote_hostio_unlink (struct target_ops *self,
>  
>  /* Implementation of to_fileio_readlink.  */
>  
> -static char *
> +static gdb::optional<std::string>
>  remote_hostio_readlink (struct target_ops *self,
>  			struct inferior *inf, const char *filename,
>  			int *remote_errno)
> @@ -11724,10 +11724,9 @@ remote_hostio_readlink (struct target_ops *self,
>    int left = get_remote_packet_size ();
>    int len, attachment_len;
>    int read_len;
> -  char *ret;
>  
>    if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
> -    return NULL;
> +    return {};
>  
>    remote_buffer_add_string (&p, &left, "vFile:readlink:");
>  
> @@ -11739,16 +11738,15 @@ remote_hostio_readlink (struct target_ops *self,
>  				    &attachment_len);
>  
>    if (len < 0)
> -    return NULL;
> +    return {};
>  
> -  ret = (char *) xmalloc (len + 1);
> +  std::string ret (len + 1, '\0');

I think it should be just "len" and not "len + 1" here.  The NULL byte is added by
the std::string on top of that length.  remote_unescape_input will only write len
bytes, so it won't touch that NULL byte.

> diff --git a/gdb/target.h b/gdb/target.h
> index 83cf48575f..05575df35f 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -935,10 +935,10 @@ struct target_ops
>         seen by the debugger (GDB or, for remote targets, the remote
>         stub).  Return a null-terminated string allocated via xmalloc,
>         or NULL if an error occurs (and set *TARGET_ERRNO).  */
> -    char *(*to_fileio_readlink) (struct target_ops *,
> -				 struct inferior *inf,
> -				 const char *filename,
> -				 int *target_errno);
> +    gdb::optional<std::string> (*to_fileio_readlink) (struct target_ops *,
> +						      struct inferior *inf,
> +						      const char *filename,
> +						      int *target_errno);

Can you update the comment above this?

LGTM with that fixed.

Simon


  parent reply	other threads:[~2018-03-07 20:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21 21:37 Tom Tromey
2018-03-07 17:29 ` Tom Tromey
2018-03-07 20:37 ` Simon Marchi [this message]
2018-03-07 22:44   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e96f8f08-4fe6-382c-4d44-7622eb824c70@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox