From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9222 invoked by alias); 29 Jun 2016 10:35:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9202 invoked by uid 89); 29 Jun 2016 10:35:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 29 Jun 2016 10:35:45 +0000 Received: by mail-wm0-f49.google.com with SMTP id f126so175082578wma.1 for ; Wed, 29 Jun 2016 03:35:44 -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=NkjWC01+9QyjUJmtrdVwhvrwfsBDTQkPbeRgqy+wRJ8=; b=UAtCt5WyVsQDwtOR8dIDsOMT2YtobYG6QU+ogd0Qlnpg4GVFQNvgoS/v4plNd8Kvbu +6uKtApeGiiWQmqZfV6ORt5C9CkNtG+baMXWhk8gxXsJhQ4ubvlrCFwdcy5/Px+MYuyP lAdhs80jSgH9A1CMCUsehcy6HKP6Y7yKbyeAQ7IJ0WC3AC87eM/QHXtAwnm/WH0oBLy1 Rij4jOE2yTQ+MKoUAdDKubG9XuKjmXBJdnNYGud8X0MiocLeTpNVL3vtqrC4eUcx+YYa t+GjL10yHaeX6449UVlJFmdVbuSqEFi50oO6sAzCKZO1Ric05Dw39ZAeHTIeBrpT8/xt jyrg== X-Gm-Message-State: ALyK8tL3rSfMKR0xGo0/2fQBeKC2xSz7o8GRdTWvm4JftQt61lR7WCTNZGBVUhM5snHi/A7MzmZxDqC5veWPQWyi X-Received: by 10.194.200.164 with SMTP id jt4mr7876502wjc.18.1467196542065; Wed, 29 Jun 2016 03:35:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.36.215 with HTTP; Wed, 29 Jun 2016 03:35:39 -0700 (PDT) In-Reply-To: References: From: Manish Goregaokar Date: Wed, 29 Jun 2016 10:35:00 -0000 Message-ID: Subject: Re: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info To: Pedro Alves , gdb-patches@sourceware.org Cc: Tom Tromey Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00501.txt.bz2 Actually, it occurs to me that token could still be null after the loop, and we use the value of token to get the name. New patch: -------------- strsep doesn't exist on Windows. 2016-06-29 Manish Goregaokar gdb/ChangeLog: * rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep. --- gdb/rust-lang.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 23ddd5a..c01687a 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; 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,7 +163,7 @@ 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))) + if (token == NULL) error (_("Invalid form for %s"), RUST_ENUM_PREFIX); value = unpack_long (member_type, valaddr + embedded_offset); -- 2.8.3 -Manish On Wed, Jun 29, 2016 at 4:01 PM, Manish Goregaokar wrote: > Fixed. > > From 6b577bb78279a453c77b08c5a1090d8dec1eeee7 Mon Sep 17 00:00:00 2001 > From: Manish Goregaokar > 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 > > 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(-) > > 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; > 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) > -- > 2.8.3 > > -Manish > > > On Wed, Jun 29, 2016 at 3:56 PM, Pedro Alves wrote: >> (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 >>> >>> 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$$$...$ >>> @@ -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 >>