From 8cac29fafce285f1bd1f51ef89a57fdde347f75a Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 19 Mar 2022 20:02:58 -0400 Subject: main: Pass NULL to time() If the argument points outside the accessible address space, Linux's time() system call returns a negative value. [1] But since this is indistinguishable from a successful report that the time is before the Epoch, glibc never actually sets errno. The Linux man-pages project recommends: "The tloc argument is obsolescent and should always be NULL in new code. When tloc is NULL, the call cannot fail." [2] [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/time/time.c [2]: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man2/time.2?id=300c07ddd873fa1abbff96262ec365271e429dab --- diff --git a/src/main.c b/src/main.c index ff6c15c..5e1f799 100644 --- a/src/main.c +++ b/src/main.c @@ -293,7 +293,7 @@ main(int argc, char * const argv[]) return EXIT_SUCCESS; } - time(&now); + now = time(NULL); dif = difftime(arg, now); if (dif >= 1000 * 24 * 60 * 60) { fputs("Date too far in the future\n", stderr); @@ -308,7 +308,7 @@ main(int argc, char * const argv[]) (int) dif / 60 % 60, (int) dif % 60); sleep(1); - time(&now); + now = time(NULL); dif = difftime(arg, now); } printf("\r000:00:00:00\n"); -- cgit v0.9.1