From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31749 invoked by alias); 16 Nov 2012 18:47:13 -0000 Received: (qmail 31738 invoked by uid 22791); 16 Nov 2012 18:47:11 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_XS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Nov 2012 18:47:05 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAGIl5en004785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Nov 2012 13:47:05 -0500 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qAGIl3pE012709 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 16 Nov 2012 13:47:04 -0500 Message-ID: <50A68A27.4090600@redhat.com> Date: Fri, 16 Nov 2012 18:47:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Tom Tromey CC: "gdb-patches@sourceware.org ml" Subject: Re: [RFA] c++/13615 References: <505119AE.6040401@redhat.com> <87sja4wlqt.fsf@fleche.redhat.com> <506F38C2.4050107@redhat.com> <874nkzhi6p.fsf@fleche.redhat.com> <87zk2rg3if.fsf@fleche.redhat.com> <50A41182.2020500@redhat.com> <87zk2iv86d.fsf@fleche.redhat.com> In-Reply-To: <87zk2iv86d.fsf@fleche.redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 X-SW-Source: 2012-11/txt/msg00469.txt.bz2 On 11/15/2012 01:59 PM, Tom Tromey wrote: > Keith> + cleanup = make_cleanup (null_cleanup, NULL); > Keith> + for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i) > Keith> + { > Keith> + const char *base_name = TYPE_BASECLASS_NAME (parent_type, i); > > First, can this ever be NULL? The comments around the declaration say it could be NULL, so I've added a guard against that. [The only two other uses of this macro in stabsread.c and valops.c both guard against this, too.] > Keith> + discard_cleanups (cleanup); > Keith> + concatenated_name = xrealloc (concatenated_name, > Keith> + (strlen (base_name) + 2 > Keith> + + strlen (name) + 1)); > Keith> + cleanup = make_cleanup (xfree, concatenated_name); > > Second, I was confused by this code the first time through -- discarding > the cleanup and then re-creating it is a bit unusual. > I think it would be simpler & cleaner to do something like: *SMACK* Duh. I seldom seem to use/remember free_current_contents! Below is the changes I've made to the patch. [I apologize if this is a bit unorthodox, but the changes are pretty small. Ping me if you want me to repost the patch in its entirety.] Keith diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index f2f79ea..deb791e 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -741,22 +741,23 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, sym = NULL; concatenated_name = NULL; - cleanup = make_cleanup (null_cleanup, NULL); + cleanup = make_cleanup (free_current_contents, &concatenated_name); for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i) { + size_t len; const char *base_name = TYPE_BASECLASS_NAME (parent_type, i); + if (base_name == NULL) + continue; + /* Search this particular base class. */ sym = cp_lookup_symbol_namespace (base_name, name, block, VAR_DOMAIN); if (sym != NULL) break; - discard_cleanups (cleanup); - concatenated_name = xrealloc (concatenated_name, - (strlen (base_name) + 2 - + strlen (name) + 1)); - cleanup = make_cleanup (xfree, concatenated_name); - sprintf (concatenated_name, "%s::%s", base_name, name); + len = strlen (base_name) + 2 + strlen (name) + 1; + concatenated_name = xrealloc (concatenated_name,len); + xsnprintf (concatenated_name, len, "%s::%s", base_name, name); sym = lookup_symbol_static (concatenated_name, block, VAR_DOMAIN); /* If there is currently no BLOCK, e.g., the inferior hasn't yet