[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGVycpbBAWUz2xCRG82ZH3EfmSR277kqgRfAznY+3Kq-iumf0Q@mail.gmail.com>
Date: Wed, 22 May 2019 09:59:32 +0800
From: luke <luke.tw@...il.com>
To: David Laight <David.Laight@...lab.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"ast@...nel.org" <ast@...nel.org>,
"daniel@...earbox.net" <daniel@...earbox.net>,
"kafai@...com" <kafai@...com>,
"songliubraving@...com" <songliubraving@...com>,
"yhs@...com" <yhs@...com>
Subject: Re: [PATCH] samples: bpf: fix: change the buffer size for read()
On Tue, May 21, 2019 at 11:05 PM David Laight <David.Laight@...lab.com> wrote:
>
> From: Chang-Hsien Tsai
> > @@ -678,7 +678,7 @@ void read_trace_pipe(void)
> > static char buf[4096];
> > ssize_t sz;
> >
> > - sz = read(trace_fd, buf, sizeof(buf));
> > + sz = read(trace_fd, buf, sizeof(buf)-1);
> > if (sz > 0) {
> > buf[sz] = 0;
> > puts(buf);
>
> Why not change the puts() to fwrite(buf, sz, 1, stdout) ?
> Then you don't need the '\0' terminator.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
Yes.
But, this will be different with the original code.
puts(buf) prints buf and a terminating newline character.
--
Chang-Hsien Tsai
Powered by blists - more mailing lists