From patchwork Sat Sep 9 00:41:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22773 Received: (qmail 28655 invoked by alias); 9 Sep 2017 00:41:43 -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 28595 invoked by uid 89); 9 Sep 2017 00:41:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Decorations X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Sep 2017 00:41:40 +0000 Received: from cmgw2 (cmgw3 [10.0.90.83]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 91333175A6C for ; Fri, 8 Sep 2017 18:41:39 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 7Chc1w01b2f2jeq01ChfUy; Fri, 08 Sep 2017 18:41:39 -0600 X-Authority-Analysis: v=2.2 cv=dZfw5Tfe c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=20KFwNOVAAAA:8 a=v2gU4mrh-PPzvd3n9-kA:9 a=gWIvE6n2mMOEw3Ze:21 a=yA6LY7Dqd2cr4QpQ:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:58538 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dqTq4-000TWc-EL; Fri, 08 Sep 2017 18:41:36 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/4] Use gdb::byte_vector in pascal_object_print_value Date: Fri, 8 Sep 2017 18:41:27 -0600 Message-Id: <20170909004129.28782-3-tom@tromey.com> In-Reply-To: <20170909004129.28782-1-tom@tromey.com> References: <20170909004129.28782-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dqTq4-000TWc-EL X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:58538 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes pascal_object_print_value to use a gdb::byte_vector. This removes a cleanup. This change also points out how the previous code had a possible use-after-free bug. gdb/ChangeLog 2017-09-08 Tom Tromey * p-valprint.c (pascal_object_print_value): Use gdb::byte_vector. --- gdb/ChangeLog | 4 ++++ gdb/p-valprint.c | 13 +++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b7f83a4..1f8bb71 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-09-08 Tom Tromey + * p-valprint.c (pascal_object_print_value): Use gdb::byte_vector. + +2017-09-08 Tom Tromey + * stack.c (func_command): Use gdb::def_vector. 2017-09-08 Keith Seitz diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 2c80233..10c2399 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -38,6 +38,7 @@ #include "cp-abi.h" #include "cp-support.h" #include "objfiles.h" +#include "common/byte-vector.h" /* Decorations for Pascal. */ @@ -730,6 +731,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr, const gdb_byte *base_valaddr = NULL; LONGEST thisoffset; int skip = 0; + gdb::byte_vector buf; if (BASETYPE_VIA_VIRTUAL (type, i)) { @@ -769,20 +771,15 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr, if (boffset < 0 || boffset >= TYPE_LENGTH (type)) { - gdb_byte *buf; - struct cleanup *back_to; + buf.resize (TYPE_LENGTH (baseclass)); - buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass)); - back_to = make_cleanup (xfree, buf); - - base_valaddr = buf; - if (target_read_memory (address + boffset, buf, + base_valaddr = buf.data (); + if (target_read_memory (address + boffset, buf.data (), TYPE_LENGTH (baseclass)) != 0) skip = 1; address = address + boffset; thisoffset = 0; boffset = 0; - do_cleanups (back_to); } else base_valaddr = valaddr;