From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126324 invoked by alias); 29 Jun 2016 10:26:15 -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 125426 invoked by uid 89); 29 Jun 2016 10:26:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=revealing, sentences X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 29 Jun 2016 10:26:13 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0693764389; Wed, 29 Jun 2016 10:26:12 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5TAQ9GL016460; Wed, 29 Jun 2016 06:26:10 -0400 Subject: Re: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info To: Manish Goregaokar , gdb-patches@sourceware.org, Tom Tromey References: From: Pedro Alves Message-ID: Date: Wed, 29 Jun 2016 10:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-06/txt/msg00499.txt.bz2 (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