From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by sourceware.org (Postfix) with ESMTPS id 3A36D385841D for ; Fri, 3 Dec 2021 14:10:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A36D385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f50.google.com with SMTP id v11so5925507wrw.10 for ; Fri, 03 Dec 2021 06:10:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=nogTG940WGD9vyQs03hl4+Ai1RxooF9SEHzQC8sUgLs=; b=t0lELNVaE20P266wcWGunWpccFcV8dE1s64NGOs1jXWFaF4MrB8TjCtVEhzTyxU90+ g+7flUT058rvGftg6Gnsw0jp6yU6fjx0G9uRZpslSuAcNoTxnU5aLEpEXC4FrApXgmmE iQ0YIf1H/9K6ThmKjCtR93LzXEkVODydJcwUYrMxSjPolg5abUGaz4RbwFq/wCVTklp2 50XlxhQ5yblEzrVFxzs7iLuiFjuBb6mwYbXVeKMI+WPi2hiYASANPaChLrOUgwQLC49g dxO3a5nO8Yop/OwEVt+WY9ScNRwmt4jkXlyMb7lO7qbBUujlGsJFPaow/zpL09/9fFBI eT8g== X-Gm-Message-State: AOAM530rw4YlGUcJ2jApDM9OrKwq5K17KwDtYhiP1ajYImpwE/p7dse5 sIh7GnRftWZapltZhsaQJpQ04+lsCcU= X-Google-Smtp-Source: ABdhPJwY5LmH+TeRoMwMMJBeS80lQOKoe5fPI37y2ZbBCp2ribk2cGfgPhsC6gvgcBNnuIGemQhmUw== X-Received: by 2002:a5d:6d01:: with SMTP id e1mr22146431wrq.157.1638540602267; Fri, 03 Dec 2021 06:10:02 -0800 (PST) Received: from ?IPV6:2001:8a0:f912:1a00:fb57:3faf:e98:b979? ([2001:8a0:f912:1a00:fb57:3faf:e98:b979]) by smtp.gmail.com with ESMTPSA id j18sm6794589wmq.44.2021.12.03.06.10.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 06:10:01 -0800 (PST) Message-ID: <636a26db-5f90-f9b7-569a-7487c7482ea7@palves.net> Date: Fri, 3 Dec 2021 14:10:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH v3 2/3] gdb: make extract_integer take an array_view Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20211201164905.702081-1-simon.marchi@polymtl.ca> <20211201164905.702081-2-simon.marchi@polymtl.ca> From: Pedro Alves In-Reply-To: <20211201164905.702081-2-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Dec 2021 14:10:05 -0000 On 2021-12-01 16:49, Simon Marchi via Gdb-patches wrote: > I think it would make sense for extract_integer, extract_signed_integer > and extract_unsigned_integer to take an array_view. This way, when we > extract an integer, we can validate that we don't overflow the buffer > passed by the caller (e.g. ask to extract a 4-byte integer but pass a > 2-byte buffer). > > - Change extract_integer to take an array_view > - Add overloads of extract_signed_integer and extract_unsigned_integer > that take array_views. Keep the existing versions so we don't > need to change all callers, but make them call the array_view > versions. > > This shortens some places like: > > result = extract_unsigned_integer (value_contents (result_val).data (), > TYPE_LENGTH (value_type (result_val)), > byte_order); > > into > > result = extract_unsigned_integer (value_contents (result_val), byte_order); > > value_contents returns an array view that is of length > `TYPE_LENGTH (value_type (result_val))` already, so the length is > implicitly communicated through the array view. LGTM.