From patchwork Fri Feb 9 13:00:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25885 Received: (qmail 33061 invoked by alias); 9 Feb 2018 13:00:32 -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 32876 invoked by uid 89); 9 Feb 2018 13:00:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 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: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Feb 2018 13:00:19 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway34.websitewelcome.com (Postfix) with ESMTP id F0C5B42AAB3 for ; Fri, 9 Feb 2018 07:00:17 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id k8Hperl7YmzEzk8Hpeu3Fi; Fri, 09 Feb 2018 07:00:17 -0600 Received: from 174-29-33-254.hlrn.qwest.net ([174.29.33.254]:60554 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ek8Hp-000o3b-N6; Fri, 09 Feb 2018 07:00:17 -0600 From: Tom Tromey To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 7/9] Use std::vector in find_source_lines References: <20180207220434.6045-1-tom@tromey.com> <20180207220434.6045-8-tom@tromey.com> Date: Fri, 09 Feb 2018 06:00:16 -0700 In-Reply-To: <20180207220434.6045-8-tom@tromey.com> (Tom Tromey's message of "Wed, 7 Feb 2018 15:04:32 -0700") Message-ID: <876076wc67.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.91 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Source-L: No X-Exim-ID: 1ek8Hp-000o3b-N6 X-Source-Sender: 174-29-33-254.hlrn.qwest.net (pokyo) [174.29.33.254]:60554 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes >>>>> "Tom" == Tom Tromey writes: Tom> + end = &data[size]; Andre pointed out that this is possibly fishy, so I think perhaps the appended should go in. Ok? Tom commit 4e40d3c76f0e14aea171c9ef7447c78defee8a74 Author: Tom Tromey Date: Fri Feb 9 05:58:46 2018 -0700 Don't reference past the end of the vector An earlier change made find_source_lines read: end = &data[size]; However, since 'size' is the size of the vector, this seems fishy. More obviously ok is to compute the end of the data directly: end = data.data () + size; 2018-02-09 Tom Tromey * source.c (find_source_lines): Don't reference past the end of the vector. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3e5b324472..d07da95027 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-02-09 Tom Tromey + + * source.c (find_source_lines): Don't reference past the end of + the vector. + 2018-02-09 Joel Brobecker * NEWS : Clarify that "rbreak" is a new diff --git a/gdb/source.c b/gdb/source.c index 9eec58febd..009bec5285 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1219,7 +1219,7 @@ find_source_lines (struct symtab *s, int desc) size = myread (desc, data.data (), size); if (size < 0) perror_with_name (symtab_to_filename_for_display (s)); - end = &data[size]; + end = data.data () + size; p = &data[0]; line_charpos[0] = 0; nlines = 1;