public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Fix off-by-one in call to vector::reserve
Date: Fri, 18 Aug 2023 08:03:46 -0600	[thread overview]
Message-ID: <20230818140346.1255946-1-tromey@adacore.com> (raw)

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


             reply	other threads:[~2023-08-18 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18 14:03 Tom Tromey [this message]
2023-08-18 16:15 ` John Baldwin
2023-08-18 19:02   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230818140346.1255946-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).