From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 95F343860765 for ; Fri, 18 Aug 2023 16:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95F343860765 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4RS6R02HHFz3QsT; Fri, 18 Aug 2023 16:15:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RS6R01TWPz3N9P; Fri, 18 Aug 2023 16:15:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692375308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kcc6f+ataF18nGrIV+omWScqCmOdozOLh3GYVSFdTYE=; b=rQAk/l/tPFuJGbjkqOAFdcPz/1rmh44ywAARgOjXNOPc6hMh7t6Hur/PSfJiUQM3TKoP2u rF/OBemkCmxWlGQjAebLKUR8kFv8g1Rr+vhTjGfAvB3iLvTVj7aCj/9Phwl+J7gHmMbs27 MMuGlb0UO+QovkrImEWYVqpcZozk/NJIeApUS/fRLID6WGyIaGWgxeZ9juwKKs968exV17 lcLEDxdQXNFuT9GCUz08TyXtSb54XXPorMHWnA/V2xRAQayDUOSvzTZ/AqSyLRqD/1Wjyi D9QiKHFvDQAZm2rg4UKXtHQuRLPER+j3/nnYqZ911jtXSB+WAXlTX/t5aHgPZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692375308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kcc6f+ataF18nGrIV+omWScqCmOdozOLh3GYVSFdTYE=; b=AFNWm0hQD0dJ4V5qUovbHJ6Hqe0hZC/lVhjNN/0MYdWcvhWT1DiE1Qy/347Ty/7sMaIy3I oQqLQYO4T2+9E7vLJIjwXFd7tBhOUkuPoYRyt+jUCkzAIFKGslXu1NyQj1RcTeFhGjYMAg +9WjFQ074rIas3bSz6awXTeCBjZPrrnCXDRQf4MdMv2NcbeMU5h4ogbImRIeTC47RD3P0e Xf2R5yjoESnuBYrS1ZSpwHG7ITjNwCN2BKxBUsUKaYp8zyia5c2CitkJSrjRwDHoth2l38 dbuYx9KOsvIlyZo+R2KhVa6vYkNrzQTgeXJJoqeiBKrNXkRe7+7Z4rvlgEuotQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692375308; a=rsa-sha256; cv=none; b=tCbQTlA7mMtYpDxCbjqhoNlhdqLVEnL+WI3uF/HhRlnriNquYLkaw029DfWXmapB7ujxM7 ONrtk8UHPWemgQwjGL8HeIyuJo59kNLbJlFcPRgpwmS7x1TsT65hDINWhbjm7be0pCWtOh qqqrOV1SwfsqotHMuks7Adh81NGqRvvZ+SM6abffc3LJd4TggXs3sqbzEE/9Pgiw/+ul5i mme7YlmADV1fYOAwJgT9e9qRZuUtj6OQkJEwjWkviclaY/P8OLiJSHwsFpToLtbsJ+l8Ki WV82zfj9oNYFfT7RCPfV0gXE6HZYkESbE+e+uJK6bY29daGjbTynDRDJKGoxQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from [IPV6:2601:648:8683:a9e0:7075:181:17d9:4b81] (unknown [IPv6:2601:648:8683:a9e0:7075:181:17d9:4b81]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4RS6Qz5sWPz1Gpt; Fri, 18 Aug 2023 16:15:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <3c557b21-d49b-cbc8-de49-237a52f8a2fb@FreeBSD.org> Date: Fri, 18 Aug 2023 09:15:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20230818140346.1255946-1-tromey@adacore.com> From: John Baldwin Subject: Re: [PATCH] Fix off-by-one in call to vector::reserve In-Reply-To: <20230818140346.1255946-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 8/18/23 7:03 AM, Tom Tromey via Gdb-patches wrote: > While looking at a bug, I noticed what I think is an off-by-one > mistake in a call to vector::reserve. This code: > > new_args.reserve (args.size ()); > new_args.push_back > (value_from_pointer (lookup_pointer_type (values_type), struct_addr)); > new_args.insert (new_args.end (), args.begin (), args.end ()); > > ... reserves 'size()' entries, but then proceeds to push one extra > one. > > This shouldn't have any really bad effects, as insert will grow the > vector. Still, it seems better to use the correct size if we're going > to bother calling reserve. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30780 > --- > gdb/infcall.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/infcall.c b/gdb/infcall.c > index bea5b185ddc..7e19be79a24 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -1233,7 +1233,7 @@ call_function_by_hand_dummy (struct value *function, > if (return_method == return_method_hidden_param) > { > /* Add the new argument to the front of the argument list. */ > - new_args.reserve (args.size ()); > + new_args.reserve (args.size () + 1); > new_args.push_back > (value_from_pointer (lookup_pointer_type (values_type), struct_addr)); > new_args.insert (new_args.end (), args.begin (), args.end ()); Pedantically speaking I would probably write it as '1 + args.size()' as the extra pointer is pushed first followed by a copy of all the items in args (that is, trying to make the expression list the sub-sizes in the same order they are added to the vector). Reviewed-by: John Baldwin -- John Baldwin