Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Manish Goregaokar <manish@mozilla.com>,
	gdb-patches@sourceware.org,        Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info
Date: Wed, 29 Jun 2016 10:26:00 -0000	[thread overview]
Message-ID: <e349e31f-74b5-a2fa-b82b-5cbb6d548f16@redhat.com> (raw)
In-Reply-To: <CAFOnWkmN-uBB8iDjMaLpe=0SxWecFXxvvgfG2-FJn3j2XbBZJA@mail.gmail.com>

(stepping in since this fixes a build breakage.)

On 06/29/2016 11:13 AM, Manish Goregaokar wrote:
> strsep doesn't exist on windows

"Windows", uppercase.

> 
> 2016-06-29  Manish Goregaokar  <manish@mozilla.com>
> 
> gdb/ChangeLog:
>     * rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep

Period at end of sentences.  Likewise on the commit log,
while at it.

> ---
>  gdb/rust-lang.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index 23ddd5a..961fdca 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -121,7 +121,7 @@ rust_get_disr_info (struct type *type, const
> gdb_byte *valaddr,
>    if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
>             strlen (RUST_ENUM_PREFIX)) == 0)
>      {
> -      char *name, *tail, *token;
> +      char *tail, *token, *name, *last = NULL;

(I don't think you need to initialize this.  If you get
a warning about it, it's likely revealing a bug.)

>        unsigned long fieldno;
>        struct type *member_type;
>        LONGEST value;
> @@ -138,6 +138,8 @@ rust_get_disr_info (struct type *type, const
> gdb_byte *valaddr,
>        cleanup = make_cleanup (xfree, name);
>        tail = name + strlen (RUST_ENUM_PREFIX);
> 
> +      token = strtok_r (tail, "$", &last);
> +
>        /* The location of the value that doubles as a discriminant is
>           stored in the name of the field, as
>           RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
> @@ -145,7 +147,7 @@ rust_get_disr_info (struct type *type, const
> gdb_byte *valaddr,
>           traversed in order to find the field (which may be several
> fields deep)
>           and the variantname is the name of the variant of the case when the
>           field is zero.  */
> -      while ((token = strsep (&tail, "$")) != NULL)
> +      do
>          {
>        if (sscanf (token, "%lu", &fieldno) != 1)

We'll now reach here even if token is NULL the first time.

>          {
> @@ -159,10 +161,8 @@ rust_get_disr_info (struct type *type, const
> gdb_byte *valaddr,
> 
>            embedded_offset += TYPE_FIELD_BITPOS (member_type, fieldno) / 8;
>            member_type = TYPE_FIELD_TYPE (member_type, fieldno);
> -        }
> +        } while ((token = strtok_r (NULL, "$", &last)) != NULL);

IMO, this calls for a "for" loop instead of a do/while.  Like:

 -      while ((token = strsep (&tail, "$")) != NULL)
 +      for (token = strtok_r (tail, "$", &saveptr);
 +           token != NULL;
 +           token = strtok_r (NULL, "$", &saveptr))
         {

Thanks,
Pedro Alves


  reply	other threads:[~2016-06-29 10:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 10:14 Manish Goregaokar
2016-06-29 10:26 ` Pedro Alves [this message]
2016-06-29 10:32   ` Manish Goregaokar
2016-06-29 10:35     ` Manish Goregaokar
2016-06-29 10:36     ` Pedro Alves
2016-06-29 10:39       ` Manish Goregaokar
2016-06-29 10:44         ` Pedro Alves

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=e349e31f-74b5-a2fa-b82b-5cbb6d548f16@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=manish@mozilla.com \
    --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