From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id BC2F53858401 for ; Fri, 18 Aug 2023 14:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC2F53858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-34bae4fa2a8so3250895ab.0 for ; Fri, 18 Aug 2023 07:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692367435; x=1692972235; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DkUu/E3GqgLgE+lsWGQ0g7pqt9ZFno0b67JBWHVLPBs=; b=VJuLUSoJ522PU8RryKIdC0lw1lGgWehDomgA6aMTG2I0aSgAn+Nwy/0g1pUokUPhq6 ANk4769rIc38vjuqW3o9yvYVtNraOSh3bUSi3sTINbkybxgcLnDsOrHmtRD0uz87Ih4X VxV9CfgEZI9RCuVTYtRS7hWra7nM0Jy16i1STzmj+xIVu11oh4r/Qi8gmA6B3wepcd1i wemTzLuMpF9zz6xaJfl/AAyoLkjlmpjZsYGRoKsBQnUJ0n4JLwuknxqwBJYGDnDeP+Aw 7kSKvR+ajw88Q3Dymi/dZVv+5qupoQunzcZTWbdMRUOY6t/pBRxFQHTV8mjOlcbyTBTQ kN7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692367435; x=1692972235; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DkUu/E3GqgLgE+lsWGQ0g7pqt9ZFno0b67JBWHVLPBs=; b=GwrPU8W7PjtH0wOGq2Jg58qVkpbwGkkvMojk+Jueo0kNlVxRaopfxJUXie+0dqcsfO qHiA6yApP3G9wRhWOni/PNR4tZtkybiXoqR4ejrTy3fHyVoT7DVzp6smlpWnmlJKyRHf ESoHWnsXj3dYLjuEIblTUf7kfYKNWijXTMVPPn6g91hSS+2nkyldPfMklty5KhEPUF8a dMpL/buHVBzj6u+EEi+RaRBlu95YTr/urqL89Uah65iCHOXq7eS9blFVoKH0f1/rNlVe hvx4QJZMl9eDsem3yDHuENyMITbqUSH0b7ZJFU697VeHNbPy11WOMoGuNwqMqFc7UxNr obrA== X-Gm-Message-State: AOJu0YwuZST8yXjL44S2qgzrGPFNyEloPMZ9LEY4GKU5baaAYlmRT7h7 j9NvGEKNKx1iHuV7zcZ6BOSwwx86uQbqRJuHjWptJw== X-Google-Smtp-Source: AGHT+IGP7EC/bdEMnFVBGdICjuQRDtbuq8GJ9e5ikqPv3MaJM5WNqyWA3e2iqIparf4FWQFPWAM9Pw== X-Received: by 2002:a92:c54d:0:b0:34a:c28f:9416 with SMTP id a13-20020a92c54d000000b0034ac28f9416mr3325030ilj.26.1692367434945; Fri, 18 Aug 2023 07:03:54 -0700 (PDT) Received: from localhost.localdomain (75-166-142-177.hlrn.qwest.net. [75.166.142.177]) by smtp.gmail.com with ESMTPSA id u20-20020a02c054000000b004182f88c368sm556257jam.67.2023.08.18.07.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 07:03:54 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix off-by-one in call to vector::reserve Date: Fri, 18 Aug 2023 08:03:46 -0600 Message-Id: <20230818140346.1255946-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: 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 ()); -- 2.40.1