Hi,

Nan Xiao wrote on Fri, Apr 20, 2018 at 05:28:01PM +0800:

> FYI, thanks!

No.  Read the manual page and /sys/kern/kern_time.c :

With a valid clock id and a valid address, this function
cannot fail, so you are just adding dead code.  Worse,
you are making future auditors wonder what the heck is
going on here.

Yours,
  Ingo


> Index: time.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/time/time.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 time.c
> --- time.c    21 Aug 2017 13:38:02 -0000      1.25
> +++ time.c    20 Apr 2018 09:21:59 -0000
> @@ -76,7 +76,8 @@ main(int argc, char *argv[])
>       if (argc < 1)
>               usage();
> 
> -     clock_gettime(CLOCK_MONOTONIC, &before);
> +     if (clock_gettime(CLOCK_MONOTONIC, &before))
> +             err(1, "clock_gettime");
>       switch(pid = vfork()) {
>       case -1:                        /* error */
>               warn("fork");
> @@ -92,7 +93,8 @@ main(int argc, char *argv[])
>       signal(SIGQUIT, SIG_IGN);
>       while (wait3(&status, 0, &ru) != pid)
>               ;
> -     clock_gettime(CLOCK_MONOTONIC, &after);
> +     if (clock_gettime(CLOCK_MONOTONIC, &after))
> +             err(1, "clock_gettime");
>       if (WIFSIGNALED(status))
>               exitonsig = WTERMSIG(status);
>       if (!WIFEXITED(status))

Reply via email to