svn commit: r319897 - head/usr.bin/yes

Xin LI delphij at gmail.com
Thu Jun 15 17:49:12 UTC 2017


Hi,

On Tue, Jun 13, 2017 at 5:35 AM, Pietro Cerutti <gahr at 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,


More information about the svn-src-all mailing list