NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/49169: Patch to make certain error messages in date(1) more specific and simplify it a bit
>Number: 49169
>Category: bin
>Synopsis: Patch to make certain error messages in date(1) more specific
>and simplify it a bit
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Aug 31 20:15:00 +0000 2014
>Originator: David H. Gutteridge
>Release: HEAD
>Organization:
>Environment:
n/a
>Description:
I've attached a patch to this PR that makes a couple of error
messages more specific and reduces the number of functions, since two
were effectively duplicates, and one seems unnecessary given it just
wraps a call to errx().
>How-To-Repeat:
Make fat-fingered typos while using date(1).
>Fix:
--- date.c.orig 2011-08-27 23:01:15.000000000 -0400
+++ date.c 2014-06-01 02:09:14.000000000 -0400
@@ -66,8 +66,6 @@
static time_t tval;
static int aflag, jflag, rflag, nflag;
-__dead static void badformat(void);
-__dead static void badtime(void);
__dead static void badvalue(const char *);
static void setthetime(const char *);
__dead static void usage(void);
@@ -162,20 +160,6 @@
}
static void
-badformat(void)
-{
- warnx("illegal time format");
- usage();
-}
-
-static void
-badtime(void)
-{
- errx(EXIT_FAILURE, "illegal time");
- /* NOTREACHED */
-}
-
-static void
badvalue(const char *param)
{
warnx("invalid %s supplied", param);
@@ -201,7 +185,7 @@
dot = t;
continue;
}
- badformat();
+ badvalue("general format");
}
if ((lt = localtime(&tval)) == NULL)
@@ -212,7 +196,7 @@
if (dot != NULL) { /* .ss */
len = strlen(dot);
if (len != 3)
- badformat();
+ badvalue("seconds");
++dot;
lt->tm_sec = ATOI2(dot);
if (lt->tm_sec > 61)
@@ -227,7 +211,7 @@
case 12: /* cc */
lt->tm_year = ATOI2(p) * 100 - TM_YEAR_BASE;
if (lt->tm_year < 0)
- badtime();
+ badvalue("century");
yearset = 1;
/* FALLTHROUGH */
case 10: /* yy */
@@ -293,12 +277,12 @@
break;
/* FALLTHROUGH */
default:
- badformat();
+ badvalue("general format");
}
/* convert broken-down time to UTC clock time */
if ((new_time = mktime(lt)) == -1)
- badtime();
+ errx(EXIT_FAILURE, "illegal time");
/* if jflag is set, don't actually change the time, just return */
if (jflag) {
Home |
Main Index |
Thread Index |
Old Index