From patchwork Wed Feb 7 22:04:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25870 Received: (qmail 4089 invoked by alias); 7 Feb 2018 22:04:45 -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 3823 invoked by uid 89); 7 Feb 2018 22:04:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.147.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 22:04:41 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 5D120C973 for ; Wed, 7 Feb 2018 16:04:40 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id jXpYecTHQODN4jXpYeWWff; Wed, 07 Feb 2018 16:04:40 -0600 Received: from 174-29-33-254.hlrn.qwest.net ([174.29.33.254]:59168 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ejXpY-002nlZ-4p; Wed, 07 Feb 2018 16:04:40 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 7/9] Use std::vector in find_source_lines Date: Wed, 7 Feb 2018 15:04:32 -0700 Message-Id: <20180207220434.6045-8-tom@tromey.com> In-Reply-To: <20180207220434.6045-1-tom@tromey.com> References: <20180207220434.6045-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1ejXpY-002nlZ-4p X-Source-Sender: 174-29-33-254.hlrn.qwest.net (pokyo.Home) [174.29.33.254]:59168 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This replaces an explicit malloc and a cleanup with a std::vector. 2018-02-07 Tom Tromey * source.c (find_source_lines): Use std::vector. --- gdb/ChangeLog | 4 ++++ gdb/source.c | 20 ++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f0ec664d23..8bd04e47c7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2018-02-07 Tom Tromey + * source.c (find_source_lines): Use std::vector. + +2018-02-07 Tom Tromey + * macrocmd.c (struct temporary_macro_definition): New. (macro_define_command): Use temporary_macro_definition. Remove cleanups. diff --git a/gdb/source.c b/gdb/source.c index 1f136f4cfb..0e871be8ca 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1186,7 +1186,7 @@ void find_source_lines (struct symtab *s, int desc) { struct stat st; - char *data, *p, *end; + char *p, *end; int nlines = 0; int lines_allocated = 1000; int *line_charpos; @@ -1207,23 +1207,20 @@ find_source_lines (struct symtab *s, int desc) warning (_("Source file is more recent than executable.")); { - struct cleanup *old_cleanups; - /* st_size might be a large type, but we only support source files whose size fits in an int. */ size = (int) st.st_size; - /* Use malloc, not alloca, because this may be pretty large, and we may - run into various kinds of limits on stack size. */ - data = (char *) xmalloc (size); - old_cleanups = make_cleanup (xfree, data); + /* Use the heap, not the stack, because this may be pretty large, + and we may run into various kinds of limits on stack size. */ + std::vector data (size); /* Reassign `size' to result of read for systems where \r\n -> \n. */ - size = myread (desc, data, size); + size = myread (desc, data.data (), size); if (size < 0) perror_with_name (symtab_to_filename_for_display (s)); - end = data + size; - p = data; + end = &data[size]; + p = &data[0]; line_charpos[0] = 0; nlines = 1; while (p != end) @@ -1239,10 +1236,9 @@ find_source_lines (struct symtab *s, int desc) (int *) xrealloc ((char *) line_charpos, sizeof (int) * lines_allocated); } - line_charpos[nlines++] = p - data; + line_charpos[nlines++] = p - data.data (); } } - do_cleanups (old_cleanups); } s->nlines = nlines;