public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: Re: [PATCH RESEND] gdb: remove static buffer in command_line_input
Date: Fri, 16 Dec 2022 14:11:48 +0000	[thread overview]
Message-ID: <ee198ede-6b39-7e9f-2b78-9ec938f17c45@palves.net> (raw)
In-Reply-To: <8a091e68-2609-b28d-3945-9b763ed9b6d0@polymtl.ca>

On 2022-12-16 1:38 p.m., Simon Marchi wrote:
> 
> 
> On 12/16/22 08:21, Pedro Alves wrote:
>> On 2022-12-15 7:06 p.m., Simon Marchi via Gdb-patches wrote:
>>>    else
>>>      {
>>>        /* Copy whole line including terminating null, and we're
>>>  	 done.  */
>>> -      buffer_grow (cmd_line_buffer, rl, len + 1);
>>> -      cmd = cmd_line_buffer->buffer;
>>> +      cmd_line_buffer.append (rl, len + 1);
>>> +      return true;
>>
>> std::string is guaranteed to be null terminated, but, it can also hold
>> \0 characters in the middle of the string.  Isn't that
>>
>>   cmd_line_buffer.append (rl, len + 1);
>>
>> ending up with an embedded \0 at the end of the string, with cmd_line_buffer.size() accounting for it?
> 
> Argh, yes!  I rewrote this patch from scratch multiple times until I got
> something satisfactory, and I know I changed that in a previous
> iteration, because I remember having that thought.
> 
> Here's a patch to fix it:
> 
> 
> From 8757d2ec9edf2ae0b77039ca0ecc9ca32fd87256 Mon Sep 17 00:00:00 2001
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Date: Fri, 16 Dec 2022 08:34:56 -0500
> Subject: [PATCH] gdb: don't copy final null character in
>  command_line_append_input_line
> 
> The modified std::string::append call currently copies the null
> character from the source string, leaving the std::string with a null
> character in its content, part of its size, in addition to the null
> character managed by the std::string itself  We don't want to copy that

Missing period after "itself".

> null character, so remove that "+ 1".
> 
> Change-Id: I412fe9bd6b08e7ce7604ef5d8038b62f1a784c9b
> ---
>  gdb/event-top.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/event-top.c b/gdb/event-top.c
> index fa86a89e4a19..fa9e1f3f6a73 100644
> --- a/gdb/event-top.c
> +++ b/gdb/event-top.c
> @@ -640,7 +640,7 @@ command_line_append_input_line (std::string &cmd_line_buffer, const char *rl)
>      {
>        /* Copy whole line including terminating null, and we're
>  	 done.  */
> -      cmd_line_buffer.append (rl, len + 1);
> +      cmd_line_buffer.append (rl, len);

I'd update the comment -- the "including terminating null" part seems
misleading now, just drop that part?

Otherwise LTGM.

>        return true;
>      }
>  }
> 
> base-commit: e60a615dde5d6674a6488b74afe807a775551407
> 

      reply	other threads:[~2022-12-16 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 19:06 Simon Marchi
2022-12-15 21:44 ` Tom Tromey
2022-12-16  2:49   ` Simon Marchi
2022-12-16 13:21 ` Pedro Alves
2022-12-16 13:38   ` Simon Marchi
2022-12-16 14:11     ` Pedro Alves [this message]

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=ee198ede-6b39-7e9f-2b78-9ec938f17c45@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.vrany@labware.com \
    --cc=simon.marchi@polymtl.ca \
    /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).