From patchwork Wed Jul 22 07:44:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciro Santilli X-Patchwork-Id: 7794 Received: (qmail 62070 invoked by alias); 22 Jul 2015 07:44:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 62060 invoked by uid 89); 22 Jul 2015 07:44:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-la0-f51.google.com Received: from mail-la0-f51.google.com (HELO mail-la0-f51.google.com) (209.85.215.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 22 Jul 2015 07:44:20 +0000 Received: by lahe2 with SMTP id e2so70314219lah.1 for ; Wed, 22 Jul 2015 00:44:17 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.212.33 with SMTP id nh1mr1050550lbc.114.1437551057336; Wed, 22 Jul 2015 00:44:17 -0700 (PDT) Received: by 10.152.1.70 with HTTP; Wed, 22 Jul 2015 00:44:17 -0700 (PDT) Date: Wed, 22 Jul 2015 09:44:17 +0200 Message-ID: Subject: [PATCH] Factor out rbreak_command with concat From: Ciro Santilli To: gdb-patches@sourceware.org X-IsSubscribed: yes The function behaviour should be unchanged. len was always 0 , so I removed it. xrealloc was always called on NULL string, so equivalent to xmalloc, which concat uses. --- gdb/ChangeLog | 4 ++++ gdb/symtab.c | 35 +++++++++-------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 407dfb4..3d8c416 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +4015-07-20 Ciro Santilli + + * symtab.c (rbreak_command): Factor with concat. + 2015-07-15 Markus Metzger Pedro Alves diff --git a/gdb/symtab.c b/gdb/symtab.c index decc5a9..015cb56 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4889,7 +4889,6 @@ rbreak_command (char *regexp, int from_tty) struct symbol_search *p; struct cleanup *old_chain; char *string = NULL; - int len = 0; const char **files = NULL; const char *file_name; int nfiles = 0; @@ -4928,20 +4927,11 @@ rbreak_command (char *regexp, int from_tty) { struct symtab *symtab = symbol_symtab (p->symbol); const char *fullname = symtab_to_fullname (symtab); - - int newlen = (strlen (fullname) - + strlen (SYMBOL_LINKAGE_NAME (p->symbol)) - + 4); - - if (newlen > len) - { - string = xrealloc (string, newlen); - len = newlen; - } - strcpy (string, fullname); - strcat (string, ":'"); - strcat (string, SYMBOL_LINKAGE_NAME (p->symbol)); - strcat (string, "'"); + string = concat(fullname, + ":'", + SYMBOL_LINKAGE_NAME (p->symbol), + "'", + (char *)NULL); break_command (string, from_tty); print_symbol_info (FUNCTIONS_DOMAIN, p->symbol, @@ -4950,17 +4940,10 @@ rbreak_command (char *regexp, int from_tty) } else { - int newlen = (strlen (MSYMBOL_LINKAGE_NAME (p->msymbol.minsym)) + 3); - - if (newlen > len) - { - string = xrealloc (string, newlen); - len = newlen; - } - strcpy (string, "'"); - strcat (string, MSYMBOL_LINKAGE_NAME (p->msymbol.minsym)); - strcat (string, "'"); - + string = concat("'", + MSYMBOL_LINKAGE_NAME (p->msymbol.minsym), + "'", + (char *)NULL); break_command (string, from_tty); printf_filtered (" %s;\n", MSYMBOL_PRINT_NAME (p->msymbol.minsym));