logo

utils-std

Collection of commonly available Unix tools
commit: 205067e912f1257ab0694176d20f64888a3acfd8
parent 144e99acf1f6b3fe17940ab40bc392432e2d9c81
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 26 Jul 2024 10:25:36 +0200

cmd/date: Handle mktime errors

Diffstat:

Mcmd/date.c15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/cmd/date.c b/cmd/date.c @@ -83,6 +83,11 @@ main(int argc, char *argv[]) assert(errno == 0); tp.tv_sec = mktime_tz(&tm); + if(tp.tv_sec == (time_t)-1) + { + fprintf(stderr, "date: mktime: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } errno = 0; break; @@ -153,6 +158,11 @@ main(int argc, char *argv[]) assert(errno == 0); tp.tv_sec = mktime_tz(&tm); tp.tv_nsec = 0; + if(tp.tv_sec == (time_t)-1) + { + fprintf(stderr, "date: mktime: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } errno = 0; argv++; @@ -196,6 +206,11 @@ main(int argc, char *argv[]) assert(errno == 0); tp.tv_sec = mktime(&tm); tp.tv_nsec = 0; + if(tp.tv_sec == (time_t)-1) + { + fprintf(stderr, "date: mktime: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } errno = 0; argv++;