Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Jun 2017 10:49:10 -0700
From:      Xin LI <delphij@gmail.com>
To:        Pietro Cerutti <gahr@freebsd.org>, cognet@freebsd.org
Cc:        "src-committers@freebsd.org" <src-committers@freebsd.org>,  "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>,  "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>
Subject:   Re: svn commit: r319897 - head/usr.bin/yes
Message-ID:  <CAGMYy3t6Dk0HR-rN3%2Bwse8tnuRJrF9bVmbNDSSUA9MQ0jXU1Fg@mail.gmail.com>
In-Reply-To: <201706131235.v5DCZ1aR077437@repo.freebsd.org>
References:  <201706131235.v5DCZ1aR077437@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

On Tue, Jun 13, 2017 at 5:35 AM, Pietro Cerutti <gahr@freebsd.org> wrote:
[...]
> Modified: head/usr.bin/yes/yes.c
> ==============================================================================
> --- head/usr.bin/yes/yes.c      Tue Jun 13 12:07:18 2017        (r319896)
> +++ head/usr.bin/yes/yes.c      Tue Jun 13 12:35:01 2017        (r319897)
> @@ -44,20 +44,42 @@ static const char rcsid[] = "$FreeBSD$";
>  int
>  main(int argc, char **argv)
>  {
[...]
> +       {
> +               exp = argv[1];
> +               explen = strlen(exp) + 1;
> +               exp[explen - 1] = '\n';
> +       }

I think this effectively replaces the terminating NUL character with
'\n', but in this context it seems to be Okay because later code is
treating argv[1] as a block of memory instead of NUL-termated string.

Could you please add comment here, so future readers would not have to
scratch their head and figure this out again and again?

By the way, in r319904, the following was introduced:

if (explen <= sizeof(buf)) {

Why do we bother to copy the buffer when the size is exactly the same
(and we could use it directly), in other words, why not explen <
sizeof(buf)?

Cheers,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGMYy3t6Dk0HR-rN3%2Bwse8tnuRJrF9bVmbNDSSUA9MQ0jXU1Fg>