From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54575 invoked by alias); 31 Dec 2017 01:31:14 -0000 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 Received: (qmail 54560 invoked by uid 89); 31 Dec 2017 01:31:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 31 Dec 2017 01:31:12 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id vBV1V6t2025611 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 30 Dec 2017 20:31:10 -0500 Received: by simark.ca (Postfix, from userid 112) id 32B731E5A3; Sat, 30 Dec 2017 20:31:06 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id BBCF21E519; Sat, 30 Dec 2017 20:31:05 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 31 Dec 2017 01:31:00 -0000 From: Simon Marchi To: Ruslan Kabatsayev Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Avoid indexing std::vector past the end In-Reply-To: <1514662273-27858-1-git-send-email-b7.10110111@gmail.com> References: <1514662273-27858-1-git-send-email-b7.10110111@gmail.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.2 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sun, 31 Dec 2017 01:31:06 +0000 X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00528.txt.bz2 On 2017-12-30 14:31, Ruslan Kabatsayev wrote: > The code here wants to find address of an element, and often this > element is one past the end of std::vector. Dereferencing that element > leads to undefined behavior, so it's better to simply use pointer > arithmetic instead of taking address of invalid dereference. > > gdb/ChangeLog: > > * psymtab.c (recursively_search_psymtabs): Use pointer arithmetic > instead of dereferencing std::vector past the end. Hi Ruslan, The patch LGTM, with a nit I missed the first time. Please push with that fixed. > --- > gdb/psymtab.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/gdb/psymtab.c b/gdb/psymtab.c > index c87ef25..c622f4c 100644 > --- a/gdb/psymtab.c > +++ b/gdb/psymtab.c > @@ -1337,21 +1337,21 @@ recursively_search_psymtabs > } > > partial_symbol **gbound > - = &objfile->global_psymbols[ps->globals_offset + > ps->n_global_syms]; > + = objfile->global_psymbols.data() + ps->globals_offset + > ps->n_global_syms; Space before parentheses, here and in the other lines. Thanks, Simon