=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.32 retrieving revision 1.37 diff -u -r1.32 -r1.37 --- src/usr.bin/calendar/day.c 2015/12/08 19:04:50 1.32 +++ src/usr.bin/calendar/day.c 2019/08/12 20:03:28 1.37 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.32 2015/12/08 19:04:50 mmcc Exp $ */ +/* $OpenBSD: day.c,v 1.37 2019/08/12 20:03:28 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -166,7 +166,7 @@ cumdays = daytab[0]; /* Friday displays Monday's events */ offset = tp->tm_wday == 5 ? 3 : 1; - if (f_SetdayAfter) + if (f_Setday) offset = 0; /* Except not when range is set explicitly */ header[5].iov_base = dayname; @@ -323,10 +323,12 @@ if (month == -1) { month = tp->tm_mon + 1; interval = MONTHLY; - } else if (calendar) - adjust_calendar(&day, &month); - if ((month > 12) || (month < 1)) - return (NULL); + } else { + if ((month > 12) || (month < 1)) + return (NULL); + if (calendar) + adjust_calendar(&day, &month); + } } /* 2. {Monthname} XYZ ... */ @@ -371,6 +373,8 @@ else { /* F_ISDAY set, v2 > 12, or no way to tell */ month = v1; + if ((month > 12) || (month < 1)) + return (NULL); /* if no recognizable day, assume the first */ day = v2 ? v2 : 1; if ((flags & F_ISDAY)) { @@ -543,8 +547,11 @@ tdiff = difftime(ttmp, f_time)/ SECSPERDAY; if (tdiff <= offset + f_dayAfter || (bodun && tdiff == -1)) { - if (tdiff >= 0 || - (bodun && tdiff == -1)) { + if (((tmtmp.tm_mon == month) || + (flags & F_SPECIAL) || + (interval == WEEKLY)) && + (tdiff >= 0 || + (bodun && tdiff == -1))) { if ((tmp = malloc(sizeof(struct match))) == NULL) err(1, NULL); tmp->when = ttmp;