git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
To: "Randall S. Becker" <rsbecker@nexbridge.com>
Cc: randall.s.becker@rogers.com, git@vger.kernel.org
Subject: Re: [Patch v1 1/3] bugreport.c: replace strbuf_write_fd with write_in_full
Date: Sat, 20 Jun 2020 06:01:41 +0700	[thread overview]
Message-ID: <20200619230141.GC5027@danh.dev> (raw)
In-Reply-To: <02a501d6465d$80366680$80a33380$@nexbridge.com>

On 2020-06-19 13:17:19-0400, "Randall S. Becker" <rsbecker@nexbridge.com> wrote:
> On June 19, 2020 12:36 PM, Đoàn Trần Công Danh wrote:
> > On 2020-06-19 11:04:43-0400, randall.s.becker@rogers.com wrote:
> > > From: "Randall S. Becker" <rsbecker@nexbridge.com>
> > >
> > > The strbuf_write_fd method did not provide checks for buffers larger
> > > than MAX_IO_SIZE. Replacing with write_in_full ensures the entire
> > > buffer will always be written to disk or report an error and die.
> > >
> > > Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>
> > > ---
> > >  bugreport.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/bugreport.c b/bugreport.c index aa8a489c35..bc359b7fa8
> > > 100644
> > > --- a/bugreport.c
> > > +++ b/bugreport.c
> > > @@ -174,7 +174,10 @@ int cmd_main(int argc, const char **argv)
> > >  		die(_("couldn't create a new file at '%s'"), report_path.buf);
> > >  	}
> > >
> > > -	strbuf_write_fd(&buffer, report);
> > > +	if (write_in_full(report, buffer.buf, buffer.len) < 0) {
> > > +		die(_("couldn't write report contents '%s' to file '%s'"),
> > > +			buffer.buf, report_path.buf);
> > 
> > Doesn't this dump the whole report to the stderr?
> > If it's the case, the error would be very hard to grasp.
> 
> Where else can we put the error? By this point, we're likely out of
> disk or virtual memory.

Sorry, I forgot to suggest an alternatives.

I was thinking about ignore the report when writing the last email.

Since, the report is likely consists of multiple lines of text,
and they likely contains some single quote themselves.

Now, I think a bit more, I think it's way better to write as:

	if (write_in_full(report, buffer.buf, buffer.len) < 0)
		die(_("couldn't write the report contents to file '%s'.\n\n"
		"The original report was:\n\n"
		"%s\n"), report_path.buf, buffer.buf);

> > Nit: We wouldn't want the pair of {}.
> > 
> > > +	}
> > >  	close(report);
> 
> I'm not sure what you mean in this nit? {} are balanced. You mean in the error message?

Our style guides says we wouldn't want this pair of {} if it's single
statement.


-- 
Danh

  parent reply	other threads:[~2020-06-19 23:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200619150445.4380-1-randall.s.becker.ref@rogers.com>
2020-06-19 15:04 ` [Patch v1 0/3] Replace strbuf_write_fd with write_in_full randall.s.becker
2020-06-19 15:04   ` [Patch v1 1/3] bugreport.c: replace " randall.s.becker
2020-06-19 16:35     ` Đoàn Trần Công Danh
2020-06-19 17:17       ` Randall S. Becker
2020-06-19 19:30         ` Junio C Hamano
2020-06-19 19:37           ` Randall S. Becker
2020-06-19 23:01         ` Đoàn Trần Công Danh [this message]
2020-06-19 23:26           ` Randall S. Becker
2020-06-19 19:47     ` Jeff King
2020-06-19 15:04   ` [Patch v1 2/3] strbuf.c: remove unreferenced strbuf_write_fd method randall.s.becker
2020-06-19 19:30     ` Junio C Hamano
2020-06-19 19:49     ` Jeff King
2020-06-19 15:04   ` [Patch v1 3/3] strbuf.h: remove declaration of deprecated " randall.s.becker
2020-06-19 19:31     ` Junio C Hamano
2020-06-19 19:34       ` Randall S. Becker

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20200619230141.GC5027@danh.dev \
    --to=congdanhqx@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=randall.s.becker@rogers.com \
    --cc=rsbecker@nexbridge.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).