summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2022-03-19 20:02:58 (EDT)
committer P. J. McDermott <pj@pehjota.net>2022-03-19 20:02:58 (EDT)
commit8cac29fafce285f1bd1f51ef89a57fdde347f75a (patch)
treecff10885f63016c33874bd0ed63976ca7b06b494
parent004891c1800b77f8a1e84030b42b100484bae8a0 (diff)
downloadatsign-8cac29fafce285f1bd1f51ef89a57fdde347f75a.zip
atsign-8cac29fafce285f1bd1f51ef89a57fdde347f75a.tar.gz
atsign-8cac29fafce285f1bd1f51ef89a57fdde347f75a.tar.bz2
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
-rw-r--r--src/main.c4
1 files changed, 2 insertions, 2 deletions
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");