Message ID | CAFOnWk=a2g-XEtsFjXp85DhTSmT4fVNSkWLuAa0WoS9JY_XM=w@mail.gmail.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 5130 invoked by alias); 29 Jun 2016 10:32:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5103 invoked by uid 89); 29 Jun 2016 10:32:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Period X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 29 Jun 2016 10:31:59 +0000 Received: by mail-wm0-f51.google.com with SMTP id f126so174944742wma.1 for <gdb-patches@sourceware.org>; Wed, 29 Jun 2016 03:31:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FS2M1RMpI1bmwoUFhfglbbrrACJEWmUVtmpQ6G+oWX8=; b=BpOCZEgEgaC1YDchLQY7YF9PFXiR3/EqzYBEkBPyRhisAcUov5XIAI3dTX2vWiWUy9 EnZnR8nYqQLIStb0PBohdkBg3VcFNE5dtdOs3enEw0ERvJHjh8/Y+BtIOZ+ZUUbwHc5p 5fRGxcEQjETXS6GRBPfPoIr9m24PQpi0a4wHoSecrQzE4tzgfuxJUo40FiktUx+GtCKF SrfbGfekXNQXAjj/b3JVAG1dXjVZ2QDT8jKwrgUu8nkt3r8vtKl9ViKFhDJO5eqjNte3 Dfp7jOkNjkAsWrF2m6Xu/Hz6maFPiRBvqwmnURWK+jC5JN9xPX8x2nYvfEy8GX9LZah0 Ojfw== X-Gm-Message-State: ALyK8tK4yjwZNvRdNGnkDIIfvWBMQjYRemjCCllJb/olW4ad7u+yHArH5NgnX+mqnp8DtVgOy5HE+nL8MOaVzVCB X-Received: by 10.28.4.140 with SMTP id 134mr21113203wme.91.1467196316727; Wed, 29 Jun 2016 03:31:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.36.215 with HTTP; Wed, 29 Jun 2016 03:31:53 -0700 (PDT) In-Reply-To: <e349e31f-74b5-a2fa-b82b-5cbb6d548f16@redhat.com> References: <CAFOnWkmN-uBB8iDjMaLpe=0SxWecFXxvvgfG2-FJn3j2XbBZJA@mail.gmail.com> <e349e31f-74b5-a2fa-b82b-5cbb6d548f16@redhat.com> From: Manish Goregaokar <manish@mozilla.com> Date: Wed, 29 Jun 2016 16:01:53 +0530 Message-ID: <CAFOnWk=a2g-XEtsFjXp85DhTSmT4fVNSkWLuAa0WoS9JY_XM=w@mail.gmail.com> Subject: Re: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info To: Pedro Alves <palves@redhat.com> Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com> Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes |
Commit Message
Manish Goregaokar
June 29, 2016, 10:31 a.m. UTC
Fixed.
From 6b577bb78279a453c77b08c5a1090d8dec1eeee7 Mon Sep 17 00:00:00 2001
From: Manish Goregaokar <manish@mozilla.com>
Date: Wed, 29 Jun 2016 15:42:28 +0530
Subject: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info
strsep doesn't exist on Windows.
2016-06-29 Manish Goregaokar <manish@mozilla.com>
gdb/ChangeLog:
* rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep.
---
gdb/rust-lang.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
LONGEST value;
@@ -145,7 +145,9 @@ 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)
+ for (token = strtok_r (tail, "$", &saveptr);
+ token != NULL;
+ token = strtok_r (NULL, "$", &saveptr))
{
if (sscanf (token, "%lu", &fieldno) != 1)
{
@@ -161,8 +163,6 @@ rust_get_disr_info (struct type *type, const
gdb_byte *valaddr,
member_type = TYPE_FIELD_TYPE (member_type, fieldno);
}
- if (token >= name + strlen (TYPE_FIELD_NAME (type, 0)))
- error (_("Invalid form for %s"), RUST_ENUM_PREFIX);
value = unpack_long (member_type, valaddr + embedded_offset);
if (value == 0)
Comments
On 06/29/2016 11:31 AM, Manish Goregaokar wrote: > @@ -161,8 +163,6 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > member_type = TYPE_FIELD_TYPE (member_type, fieldno); > } > > - if (token >= name + strlen (TYPE_FIELD_NAME (type, 0))) > - error (_("Invalid form for %s"), RUST_ENUM_PREFIX); > value = unpack_long (member_type, valaddr + embedded_offset); > > if (value == 0) Why was this bit removed? Thanks, Pedro Alves
strsep moves the pointer to the end of the string. We want to ensure the early break happens, since we need token to contain the name of the variant at this stage. strtok doesn't do this. However, strtok does make it NULL, which we don't want either. I added a check for it in my most recent email, tests still pass. Thanks, -Manish On Wed, Jun 29, 2016 at 4:06 PM, Pedro Alves <palves@redhat.com> wrote: > On 06/29/2016 11:31 AM, Manish Goregaokar wrote: >> @@ -161,8 +163,6 @@ rust_get_disr_info (struct type *type, const >> gdb_byte *valaddr, >> member_type = TYPE_FIELD_TYPE (member_type, fieldno); >> } >> >> - if (token >= name + strlen (TYPE_FIELD_NAME (type, 0))) >> - error (_("Invalid form for %s"), RUST_ENUM_PREFIX); >> value = unpack_long (member_type, valaddr + embedded_offset); >> >> if (value == 0) > > Why was this bit removed? > > Thanks, > Pedro Alves >
On 06/29/2016 11:38 AM, Manish Goregaokar wrote: > strsep moves the pointer to the end of the string. We want to ensure > the early break happens, since we need token to contain the name of > the variant at this stage. > > strtok doesn't do this. However, strtok does make it NULL, which we > don't want either. I added a check for it in my most recent email, > tests still pass. Right, that one is OK. Please push. Thanks, Pedro Alves
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 23ddd5a..5910d4b 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, *saveptr; unsigned long fieldno; struct type *member_type;