NetBSD Problem Report #49169
From www@NetBSD.org Sun Aug 31 20:12:47 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 65C6EB78BD
for <gnats-bugs@gnats.NetBSD.org>; Sun, 31 Aug 2014 20:12:47 +0000 (UTC)
Message-Id: <20140831201245.D4D40B78C4@mollari.NetBSD.org>
Date: Sun, 31 Aug 2014 20:12:45 +0000 (UTC)
From: dhgutteridge@sympatico.ca
Reply-To: dhgutteridge@sympatico.ca
To: gnats-bugs@NetBSD.org
Subject: Patch to make certain error messages in date(1) more specific and simplify it a bit
X-Send-Pr-Version: www-1.0
>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: closed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Aug 31 20:15:00 +0000 2014
>Closed-Date: Tue Sep 02 05:54:30 +0000 2014
>Last-Modified: Tue Sep 02 05:54:30 +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) {
>Release-Note:
>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/49169 CVS commit: src/bin/date
Date: Mon, 1 Sep 2014 21:42:21 +0000
Module Name: src
Committed By: dholland
Date: Mon Sep 1 21:42:21 UTC 2014
Modified Files:
src/bin/date: date.c
Log Message:
Provide real error messages.
Inspired by PR 49169 from David H. Gutteridge, but a much broader patch :-)
To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/bin/date/date.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 01 Sep 2014 21:52:08 +0000
State-Changed-Why:
you like? :-)
From: "David H. Gutteridge" <dhgutteridge@sympatico.ca>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/49169 (Patch to make certain error messages in date(1) more specific and simplify it a bit)
Date: Mon, 1 Sep 2014 20:01:36 -0400
Very thorough, thanks!
Dave
State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Tue, 02 Sep 2014 05:54:30 +0000
State-Changed-Why:
Fixed.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.