NetBSD Problem Report #41945
From wiz@yt.nih.at Wed Aug 26 23:24:07 2009
Return-Path: <wiz@yt.nih.at>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id 8C4F963B121
for <gnats-bugs@gnats.NetBSD.org>; Wed, 26 Aug 2009 23:24:07 +0000 (UTC)
Message-Id: <20090826232403.B275939FEA3@yt.nih.at>
Date: Thu, 27 Aug 2009 01:24:03 +0200 (CEST)
From: Thomas Klausner <wiz@NetBSD.org>
Reply-To: Thomas Klausner <wiz@NetBSD.org>
To: gnats-bugs@gnats.NetBSD.org
Subject: calendar(1) doesn't recognize days of the week correctly sometimes
X-Send-Pr-Version: 3.95
>Number: 41945
>Category: bin
>Synopsis: calendar(1) doesn't recognize days of the week correctly sometimes
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Aug 26 23:25:00 +0000 2009
>Closed-Date: Tue Dec 08 13:49:43 +0000 2009
>Last-Modified: Tue Dec 08 13:50:01 +0000 2009
>Originator: Thomas Klausner
>Release: NetBSD 5.99.15
>Organization:
>Environment:
System: NetBSD yt 5.99.15 NetBSD 5.99.15 (YT) #0: Sun Aug 23 18:56:00 CEST 2009 wiz@yt:/archive/cvs/src/sys/arch/amd64/compile/obj/YT amd64
Architecture: x86_64
Machine: amd64
>Description:
With the following .calendar/calendar file, consisting of just one line:
Friday A
Run "calendar" for Monday, July 6, 2009, i.e.
calender -d 0706
Wonder why it mentions
Friday A
in the output.
This error doesn't happen for all dates, usually Mondays are free of
reports for Fridays; e.g. calendar -d 0713 is fine.
>How-To-Repeat:
See above.
>Fix:
Not provided.
>Release-Note:
>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week
correctly sometimes
Date: Thu, 27 Aug 2009 04:28:40 +0000
On Wed, Aug 26, 2009 at 11:25:01PM +0000, Thomas Klausner wrote:
> With the following .calendar/calendar file, consisting of just one line:
> Friday A
> Run "calendar" for Monday, July 6, 2009, i.e.
> calendar -d 0706
> Wonder why it mentions
> Friday A
> in the output.
The problem is that it's conflating days of the week with days of the
month. Friday is day 6 of the week, apparently.
The logic involved is structured with chewing gum and fixing it
robustly does not look to be entirely trivial. :-/
--
David A. Holland
dholland@netbsd.org
From: Robert Elz <kre@munnari.OZ.AU>
To: David Holland <dholland-bugs@NetBSD.org>
Cc: gnats-bugs@NetBSD.org, gnats-admin@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 14 Oct 2009 17:31:03 +0700
Date: Thu, 27 Aug 2009 04:28:40 +0000
From: David Holland <dholland-bugs@NetBSD.org>
Message-ID: <20090827042840.GA12220@netbsd.org>
| The problem is that it's conflating days of the week with days of the
| month. Friday is day 6 of the week, apparently.
No, it is much simpler than that, a beginners programming bug....
| The logic involved is structured with chewing gum and fixing it
| robustly does not look to be entirely trivial. :-/
Try the patch below.
It seems as if someone believed that
if (f & (A|B))
means "if both A and B are set in f" - that's obvious, as the code
does (essentially)
if (f & (A|B))
return (1);
if (f & A)
/* other stuff */
in which the other stuff cannot possibly be executed, as if A was
set, we would have already returned.
The patch just rewrites those tests to be
if ((f & (A|B)) == (A|B))
which is clearly what the code author intended.
How this has lasted in calendar all this time (and unnoticed) I
hate to imagine - I guess very few people ever use this thing
(and at that, just how many of us system admins do what the man
page says and set the system holiday files correctly for the current year,
every year...)
kre
--- /usr/src/usr.bin/calendar/calendar.c 2005-07-15 16:45:04.000000000 +0700
+++ calendar.c 2009-10-14 17:23:43.000000000 +0700
@@ -276,13 +276,15 @@
}
}
- if (flags & (F_WILDMONTH|F_WILDDAY))
+ if ((flags & (F_WILDMONTH|F_WILDDAY)) == (F_WILDMONTH|F_WILDDAY))
return (1);
- if ((flags & (F_WILDMONTH|F_ISDAY)) && (day == tp->tm_mday))
+ if (((flags & (F_WILDMONTH|F_ISDAY)) == (F_WILDMONTH|F_ISDAY)) &&
+ (day == tp->tm_mday))
return (1);
- if ((flags & (F_ISMONTH|F_WILDDAY)) && (month == tp->tm_mon + 1))
+ if (((flags & (F_ISMONTH|F_WILDDAY)) == (F_ISMONTH|F_WILDDAY)) &&
+ (month == tp->tm_mon + 1))
return (1);
if (flags & F_ISDAY)
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 14 Oct 2009 18:30:18 +0700
Date: Wed, 14 Oct 2009 10:35:01 +0000 (UTC)
From: Robert Elz <kre@munnari.OZ.AU>
Message-ID: <20091014103501.E26CC63B877@www.NetBSD.org>
| Try the patch below.
Ignore that noise, sorry - that was a patch against a very old
version of calendar.c ... and what's more the problem it fixed
was fixed in a different way in more up to date sources (but
apparently not correctly). I'll see if I can find out what
is wrong with the current version, and send a patch for that one.
kre
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 14 Oct 2009 18:58:59 +0700
Try this patch (against current) instead of the nonsense I sent
before, it turns out another logic change that was added to the isnow()
function caused this bug to reappear even though the (f & (A|B)) stuff
had been fixed.
Solution this time is to separate out the concept of day of month from
day of the week, and treat them differently. This means that you can
no longer write
6 entry
and have it mean "every friday" which you (sort of) could before, now
if you mean friday you have to use the name, and if you mean a date,
you have to use its number.
kre
--- /release/current/usr/src/usr.bin/calendar/calendar.c 2008-09-30 12:51:41.000000000 +0700
+++ calendar.c 2009-10-14 18:48:27.000000000 +0700
@@ -251,6 +251,7 @@
#define F_ISDAY 0x02
#define F_WILDMONTH 0x04
#define F_WILDDAY 0x08
+#define F_ISDOW 0x10
flags = 0;
@@ -258,7 +259,7 @@
if (!(v1 = getfield(endp, &endp, &flags)))
return false;
- if (flags & F_ISDAY || v1 > 12) {
+ if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
/* found a day */
day = v1;
/* if no recognizable month, assume wildcard ('*') month */
@@ -295,10 +296,17 @@
if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
return true;
+ if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday)
+ return true;
+
if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
return true;
- if (flags & F_ISDAY)
+ if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 &&
+ day == tp->tm_wday)
+ return true;
+
+ if (flags & F_ISDOW)
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
day = cumdays[month] + day;
@@ -350,7 +358,7 @@
if ((val = getmonth(start)) != 0)
*flags |= F_ISMONTH;
else if ((val = getday(start)) != 0)
- *flags |= F_ISDAY;
+ *flags |= F_ISDOW;
else {
*p = savech;
return 0;
From: Thomas Klausner <wiz@NetBSD.org>
To: Robert Elz <kre@munnari.OZ.AU>
Cc: NetBSD bugtracking <gnats-bugs@NetBSD.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week
correctly sometimes
Date: Tue, 20 Oct 2009 15:20:44 +0200
Hi Robert!
Thanks for the patch. It works much better than what we have now.
# ./calendar -d 1006
# calendar -d 1006
Friday 2000 something
Friday Something else
However, there's one bug left, I think:
# ./calendar -d 1005
Sunday 1800 something
The 5th was a Monday. Perhaps the Sunday is caught by the lookahead
for the weekend on Fridays (5)?
While testing it, I found that -f doesn't work as expected -- I gave
it the same file containting the two entries (and more) cited above,
but it doesn't show anything for that file, independent from date.
Perhaps because that file tries including other files and those are
not found since CALENDAR_DIR is not set (the files are in the same
dir). There is no error message though.
Thanks,
Thomas
From: "Jeremy C. Reed" <reed@reedmedia.net>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week
correctly sometimes
Date: Tue, 20 Oct 2009 08:45:23 -0500 (CDT)
I don't know if this is related, but see
http://mail-index.netbsd.org/tech-userlevel/2008/05/05/msg000543.html
I received several emails off-list including patches I have been using
for 18 months now. I will email the developers to ask them to commit the
fixes.
From: Robert Elz <kre@munnari.OZ.AU>
To: Thomas Klausner <wiz@NetBSD.org>, "Jeremy C. Reed" <reed@reedmedia.net>
Cc: NetBSD bugtracking <gnats-bugs@NetBSD.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 21 Oct 2009 00:10:07 +0700
Date: Tue, 20 Oct 2009 15:20:44 +0200
From: Thomas Klausner <wiz@NetBSD.org>
Message-ID: <20091020132044.GY13087@danbala.tuwien.ac.at>
| However, there's one bug left, I think:
| # ./calendar -d 1005
| Sunday 1800 something
|
| The 5th was a Monday. Perhaps the Sunday is caught by the lookahead
| for the weekend on Fridays (5)?
Try using -l 0 and see if that makes a difference, the lookahead stuff
is wacko, the weekend variation is just plain insane (IMO). But that's
what it is supposed to do, so ...
| While testing it, I found that -f doesn't work as expected
I'll see if I can see anything weird in that, but if you haven't heard from
me by this time tomorrow, it will be (at least) next week sometime.
Are you attempting (or expecting) to have the cpp nonsense work?
I'll also take a look at Jeremey's tests from his 2008 message, and see how
much of that is still broken. Jeremey, if you want to send me either the
calendar.c with the patches you're using in it, or the patches you received,
I'll see if I can reconcile it all. Then someone can commit it, perhaps...
kre
From: Thomas Klausner <wiz@NetBSD.org>
To: Robert Elz <kre@munnari.OZ.AU>
Cc: "Jeremy C. Reed" <reed@reedmedia.net>,
NetBSD bugtracking <gnats-bugs@NetBSD.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week
correctly sometimes
Date: Tue, 20 Oct 2009 21:54:58 +0200
On Wed, Oct 21, 2009 at 12:10:07AM +0700, Robert Elz wrote:
> Date: Tue, 20 Oct 2009 15:20:44 +0200
> From: Thomas Klausner <wiz@NetBSD.org>
> Message-ID: <20091020132044.GY13087@danbala.tuwien.ac.at>
>
> | However, there's one bug left, I think:
> | # ./calendar -d 1005
> | Sunday 1800 something
> |
> | The 5th was a Monday. Perhaps the Sunday is caught by the lookahead
> | for the weekend on Fridays (5)?
>
> Try using -l 0 and see if that makes a difference, the lookahead stuff
> is wacko, the weekend variation is just plain insane (IMO). But that's
> what it is supposed to do, so ...
./calendar -d 1005 -l 0
gives me the same line.
> Are you attempting (or expecting) to have the cpp nonsense work?
Yes, "#include <foo>" usually works with files in ~/.calendar and
CALENDAR_DIR set to it. I just found this issue because I was using a
remote backup and the file I was using for tests wasn't in
~/.calendar.
> I'll also take a look at Jeremey's tests from his 2008 message, and see how
> much of that is still broken. Jeremey, if you want to send me either the
> calendar.c with the patches you're using in it, or the patches you received,
> I'll see if I can reconcile it all. Then someone can commit it, perhaps...
Sounds good, thanks!
Thomas
From: Robert Elz <kre@munnari.OZ.AU>
To: Thomas Klausner <wiz@NetBSD.org>
Cc: NetBSD bugtracking <gnats-bugs@NetBSD.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 21 Oct 2009 04:07:50 +0700
Date: Tue, 20 Oct 2009 15:20:44 +0200
From: Thomas Klausner <wiz@NetBSD.org>
Message-ID: <20091020132044.GY13087@danbala.tuwien.ac.at>
| Perhaps because that file tries including other files and those are
| not found since CALENDAR_DIR is not set (the files are in the same
| dir).
On this part, I believe that files included (if not including a
full path name) are searched for in either CALENDAR_DIR (if given) or
$HOME (otherwise), and also /usr/share/calendar (and most probably
/usr/include ...)
Unlike C, the directory containing the canendar file, unless it is one
of the above, is not searched (not even for #include "file") - it can't
be, as cpp has no idea where that would be (it is passed the calendar file
via stdin, not via a path name arg).
This is probably all bogus, when I make a patch, I'll see if I can make
that more rational.
| There is no error message though.
This one I'm not sure I understand (yet), I see nothinh that should
inhibit cpp error messages, but I'm also not sure I really understand gcc's
cpp.
kre
From: Robert Elz <kre@munnari.OZ.AU>
To: Thomas Klausner <wiz@netbsd.org>
Cc: "Jeremy C. Reed" <reed@reedmedia.net>,
NetBSD bugtracking <gnats-bugs@netbsd.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 21 Oct 2009 17:05:49 +0700
Date: Tue, 20 Oct 2009 21:54:58 +0200
From: Thomas Klausner <wiz@NetBSD.org>
Message-ID: <20091020195458.GE13087@danbala.tuwien.ac.at>
| Sounds good, thanks!
OK, here's a replacement patch - this is just for (most of the) parsing
bugs that you mentioned, and those from Jeremy Reed's message
http://mail-index.netbsd.org/tech-userlevel/2008/05/05/msg000543.html
which was reporting essentially the same set of bugs.
This is just for the calendar line parser bugs, no changes to the
way cpp is invoked yet, so expecting
#include "file"
to find "file" in the same directory as the calendar file, except
bu fluke (the calendar file is in the "right place") is still not
going to work, but it is possible to
#include <stdio.h>
and that "works" ... Still no idea why you wouldn't have gotten an
error message if the file you included wasn't found, unless a file of
the same name did exist somewhere that calendar would look (unless it
happens to have canendar style lines in it, referencing a bogus file
is mostly just silently ignored).
There's one bug mentioned in Jeremy's mail that this doesn't fix, because
fixing that one is a significantly bigger change than I have time for
right now.
That is ...
5) Multiple entries for same day or missed:
tx:work$ calendar -d 0504 -f /home/reed/calendar.test
*Monday *Monday
Wednesday Today is Wednesday
*Wednesday *Wednesday
** **
See my other Wednesday entry in calendar.test above.
The "missing" entry from the calendar file given was
Wednesday Wednesday
It isn't missed because it is a duplicate, but because it starts with
two day names, and that just confuses the parser, if the line had been
Wednesday is Wednesday
or something, it would have worked just fine (well, subject to the other
bugs that exist anyway - that line shouldn't have apepared in that test
at all, as 0504 (in 2008 when the message was sent) was a Sunday. But
when Wednesday lines should be printed, it would be.
This patch doesn't attempt to fix that, or various other "unusual"
formats for calendar type lines that cause strange things to happen.
I am going to send a message to netbsd-users about another possible
change that might be needed, to ask for what people think.
kre
ps; this patch is based upon src/usr.bin/calendar/calendar.c from
current as it is today (1.47). Discard my earlier versions in this PR.
--- /release/current/usr/src/usr.bin/calendar/calendar.c 2008-09-30 12:51:41.000000000 +0700
+++ calendar.c 2009-10-21 16:26:26.000000000 +0700
@@ -63,6 +63,13 @@
#include "pathnames.h"
+ /* flags used by calendar file parser */
+#define F_ISMONTH 0x01
+#define F_ISDAY 0x02
+#define F_ISDOW 0x04
+#define F_WILDMONTH 0x10
+#define F_WILDDAY 0x20
+
static unsigned short lookahead = 1;
static unsigned short weekend = 2;
static char *fname = NULL;
@@ -247,18 +254,13 @@
int v1;
int v2;
-#define F_ISMONTH 0x01
-#define F_ISDAY 0x02
-#define F_WILDMONTH 0x04
-#define F_WILDDAY 0x08
-
flags = 0;
/* didn't recognize anything, skip it */
if (!(v1 = getfield(endp, &endp, &flags)))
return false;
- if (flags & F_ISDAY || v1 > 12) {
+ if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
/* found a day */
day = v1;
/* if no recognizable month, assume wildcard ('*') month */
@@ -295,10 +297,17 @@
if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
return true;
+ if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday + 1)
+ return true;
+
if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
return true;
- if (flags & F_ISDAY)
+ if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 &&
+ day == tp->tm_wday + 1)
+ return true;
+
+ if (flags & F_ISDOW)
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
day = cumdays[month] + day;
@@ -343,17 +352,20 @@
*endp = p;
return val;
}
- for (start = p; *p != '\0' && isalpha((unsigned char)*++p); /*EMPTY*/)
+ for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++)
continue;
- savech = *p;
- *p = '\0';
- if ((val = getmonth(start)) != 0)
- *flags |= F_ISMONTH;
- else if ((val = getday(start)) != 0)
- *flags |= F_ISDAY;
- else {
- *p = savech;
- return 0;
+ if (p != start) {
+ savech = *p;
+ *p = '\0';
+ if ((val = getmonth(start)) != 0)
+ *flags |= F_ISMONTH;
+ else if ((val = getday(start)) != 0)
+ *flags |= F_ISDOW;
+ else {
+ *p = savech;
+ *endp = start;
+ return 0;
+ }
}
for (*p = savech; FLDCHAR(*p); ++p)
continue;
From: Thomas Klausner <wiz@netbsd.org>
To: Robert Elz <kre@munnari.OZ.AU>
Cc: NetBSD bugtracking <gnats-bugs@NetBSD.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week
correctly sometimes
Date: Tue, 17 Nov 2009 16:41:00 +0100
On Wed, Oct 21, 2009 at 05:05:49PM +0700, Robert Elz wrote:
> OK, here's a replacement patch - this is just for (most of the) parsing
> bugs that you mentioned, and those from Jeremy Reed's message
> http://mail-index.netbsd.org/tech-userlevel/2008/05/05/msg000543.html
> which was reporting essentially the same set of bugs.
I've just (sorry for the late reply...) tried it and got a compilation
error:
# USETOOLS=no make
rm -f .gdbinit
touch .gdbinit
# compile calendar/calendar.o
cc -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare -Wno-traditional -Wa,--fatal-warnings -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wsign-compare -std=gnu99 -Werror -c calendar.c
cc1: warnings being treated as errors
calendar.c: In function 'getfield':
calendar.c:330: warning: 'savech' may be used uninitialized in this function
calendar.c:328: warning: 'val' may be used uninitialized in this function
*** Error code 1
Thomas
From: Robert Elz <kre@munnari.OZ.AU>
To: Thomas Klausner <wiz@netbsd.org>
Cc: NetBSD bugtracking <gnats-bugs@netbsd.org>
Subject: Re: bin/41945: calendar(1) doesn't recognize days of the week correctly sometimes
Date: Wed, 18 Nov 2009 16:48:46 +0700
Date: Tue, 17 Nov 2009 16:41:00 +0100
From: Thomas Klausner <wiz@netbsd.org>
Message-ID: <20091117154100.GM10767@danbala.tuwien.ac.at>
| calendar.c:330: warning: 'savech' may be used uninitialized in this function
Oops - that one was me, attempting an optimisation, then not compiling
with warnings on to notice I screwed up...
| calendar.c:328: warning: 'val' may be used uninitialized in this function
That's caused by the same thing, but is harmless, val can be used
unintialised, but no-one cares, the flags field indicates whether val
contains anything or not (and if it does, what kind of data is there),
and the flags are only ever set after val has been set, so this one would
be safe (ignoring theoretical unknown processors that trap on references
to unit data ... which I tend to do). But I have added an init of the
variable just to make the warning go away.
Try the appended patch instead (made against today's CVS version of
calendar.c from the head - which is probably the same as it was last
time, but I didn't check...)
I also added a comment on the (very weird) FLDCHAR() macro, which takes
an arg, that it never actually uses, but which still seems like the right
way to write it...
kre
ps: I still suspect that discarding our (ancient) calendar and restarting
with the current FreeBSD version would probably be a net win.
--- /tmp/calendar.c 2009-11-18 16:35:43.000000000 +0700
+++ calendar.c 2009-11-18 16:44:18.000000000 +0700
@@ -63,6 +63,13 @@
#include "pathnames.h"
+ /* flags used by calendar file parser */
+#define F_ISMONTH 0x01
+#define F_ISDAY 0x02
+#define F_ISDOW 0x04
+#define F_WILDMONTH 0x10
+#define F_WILDDAY 0x20
+
static unsigned short lookahead = 1;
static unsigned short weekend = 2;
static char *fname = NULL;
@@ -247,18 +254,13 @@
int v1;
int v2;
-#define F_ISMONTH 0x01
-#define F_ISDAY 0x02
-#define F_WILDMONTH 0x04
-#define F_WILDDAY 0x08
-
flags = 0;
/* didn't recognize anything, skip it */
if (!(v1 = getfield(endp, &endp, &flags)))
return false;
- if (flags & F_ISDAY || v1 > 12) {
+ if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
/* found a day */
day = v1;
/* if no recognizable month, assume wildcard ('*') month */
@@ -295,10 +297,17 @@
if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
return true;
+ if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday + 1)
+ return true;
+
if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
return true;
- if (flags & F_ISDAY)
+ if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 &&
+ day == tp->tm_wday + 1)
+ return true;
+
+ if (flags & F_ISDOW)
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
day = cumdays[month] + day;
@@ -320,9 +329,15 @@
char *start;
char savech;
+/*
+ * note this macro has an arg that isn't used ... it is retained
+ * (it is believed) to make the macro call look more "natural"
+ * and suggest at the call site what is happening.
+ */
#define FLDCHAR(a) (*p != '\0' && !isdigit((unsigned char)*p) && \
!isalpha((unsigned char)*p) && *p != '*')
+ val = 0;
for (/*EMPTY*/; FLDCHAR(*p); ++p)
continue;
if (*p == '*') { /* `*' is current month */
@@ -343,17 +358,21 @@
*endp = p;
return val;
}
- for (start = p; *p != '\0' && isalpha((unsigned char)*++p); /*EMPTY*/)
+ for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++)
continue;
+
savech = *p;
- *p = '\0';
- if ((val = getmonth(start)) != 0)
- *flags |= F_ISMONTH;
- else if ((val = getday(start)) != 0)
- *flags |= F_ISDAY;
- else {
- *p = savech;
- return 0;
+ if (p != start) {
+ *p = '\0';
+ if ((val = getmonth(start)) != 0)
+ *flags |= F_ISMONTH;
+ else if ((val = getday(start)) != 0)
+ *flags |= F_ISDOW;
+ else {
+ *p = savech;
+ *endp = start;
+ return 0;
+ }
}
for (*p = savech; FLDCHAR(*p); ++p)
continue;
State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Tue, 08 Dec 2009 13:49:43 +0000
State-Changed-Why:
Committed Robert's patch, thanks Robert!
From: Thomas Klausner <wiz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/41945 CVS commit: src/usr.bin/calendar
Date: Tue, 8 Dec 2009 13:49:08 +0000
Module Name: src
Committed By: wiz
Date: Tue Dec 8 13:49:08 UTC 2009
Modified Files:
src/usr.bin/calendar: calendar.c
Log Message:
Fix problem of reporting wrong matches noted in PR 41945 by using a patch
provided by Robert Elz in that PR.
To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/calendar/calendar.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>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-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.