From 4534eb02981fe560239c0331b575f6d9fd46592b Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Wed, 7 Dec 2005 12:31:06 +0000 Subject: Tidy up month parsing: don't accept "mayor" for "may", or "4x" for "4". And strptime(3) %b and %B conversions are the same, so don't bother trying both. ok otto@ --- usr.bin/cal/cal.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'usr.bin/cal') diff --git a/usr.bin/cal/cal.c b/usr.bin/cal/cal.c index 428b9848df6..b5676a147b8 100644 --- a/usr.bin/cal/cal.c +++ b/usr.bin/cal/cal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cal.c,v 1.16 2005/09/25 21:05:04 jmc Exp $ */ +/* $OpenBSD: cal.c,v 1.17 2005/12/07 12:31:05 tom Exp $ */ /* $NetBSD: cal.c,v 1.6 1995/03/26 03:10:24 glass Exp $ */ /* @@ -40,7 +40,7 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94"; #else -static const char rcsid[] = "$OpenBSD: cal.c,v 1.16 2005/09/25 21:05:04 jmc Exp $"; +static const char rcsid[] = "$OpenBSD: cal.c,v 1.17 2005/12/07 12:31:05 tom Exp $"; #endif #endif /* not lint */ @@ -434,13 +434,12 @@ parsemonth(const char *s) int v; v = (int)strtol(s, &cp, 10); - if (cp != s) - ; - else if (strptime(s, "%B", &tm) != NULL) - v = tm.tm_mon + 1; - else if (strptime(s, "%b", &tm) != NULL) - v = tm.tm_mon + 1; + if (*cp != '\0') { /* s wasn't purely numeric */ + v = 0; + if ((cp = strptime(s, "%b", &tm)) != NULL && *cp == '\0') + v = tm.tm_mon + 1; + } if (v <= 0 || v > 12) - errx(1, "illegal month value: use 1-12"); + errx(1, "invalid month: use 1-12 or a name"); return (v); } -- cgit v1.2.3