From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125511 invoked by alias); 6 Jan 2020 13:03:29 -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 125499 invoked by uid 89); 6 Jan 2020 13:03:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Isnt, Isn't X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Jan 2020 13:03:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578315806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WvRvY3MINbUL7qFNiuAHlQhfZzGk0tJCXUCWibg6fmI=; b=Ktx/i6XJsagoOamWHrDPwwHiDw+vLhYxVa1fvo3O0PWHObtgyhkiwCTWsruJPuI8eQ9hoT 0OPhf8+N5kE+GW6cq8nMjQjGFB1UqD6caCPvKjVj/LiNDuqH7YxvPkSFsw1iC+24+TVIEH xJVVkUCEd7R7w8GvjU4E8NFquBCBbPg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-tfKlqqGlN3OJDv10l0Y9sg-1; Mon, 06 Jan 2020 08:03:23 -0500 Received: by mail-wr1-f69.google.com with SMTP id d8so20602268wrq.12 for ; Mon, 06 Jan 2020 05:03:21 -0800 (PST) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id n189sm23330150wme.33.2020.01.06.05.03.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jan 2020 05:03:20 -0800 (PST) Subject: Re: [PATCH v2] GDB: Fix the overflow in addr_is_displayed() To: Shahab Vahedi References: <20200106102649.15710-1-shahab.vahedi@gmail.com> <11035b53-bb43-740a-de38-6283062cdc6d@redhat.com> <20200106124353.GB1101@gmail.com> Cc: gdb-patches@sourceware.org, Shahab Vahedi , Claudiu Zissulescu , Francois Bedard From: Pedro Alves Message-ID: <45a718f7-e905-e7b1-1596-6ef6c4204176@redhat.com> Date: Mon, 06 Jan 2020 13:03:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20200106124353.GB1101@gmail.com> X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2020-01/txt/msg00108.txt.bz2 On 1/6/20 12:43 PM, Shahab Vahedi wrote: > How does this look? > > bool is_displayed = false; > int threshold = SCROLL_THRESHOLD; > > - int i = 0; > - while (i < content.size () - threshold && !is_displayed) > + if (content.size () < threshold) > + return is_displayed; > + I'd write "false" instead of "is_displayed", to remove the indirection. Actually, do we really need the "threshold" variable, btw? Or even, "is_displayed"? Isn't the following equivalent? if (content.size () < SCROLL_THRESHOLD) return false; for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; i++) { if (content[i].line_or_addr.loa == LOA_ADDRESS && content[i].line_or_addr.u.addr == addr) return true; } return false; Anyway, what you have is fine too. More importantly, doesn't tui_source_window::line_is_displayed have the exact same issue? Thanks, Pedro Alves