HylaFAX The world's
most advanced open source fax server
|
|
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
Re: FW: WARNING! Hylafax Y2K bug found
Hi Ken,
At 10:21 AM 5/14/99 -0500, Ken Cornetet wrote:
>I tried sending this a couple of days ago, but I'm not sure it hit the list.
>I've checked www.hylafax.org and my note wasn't in the archive. Also, the
>web page still claims there are no Y2K issues known.
Much thanks for finding this problem, i have attached a patch which also
should fix the problem but slightly differently. To make the whole thing a
bit more type safe so that it will be harder to make the same or the
reverse error in future.
If i have not made any stupid mistakes in the patch(someone please test!) i
will commit it and update the web page.
>I'd like to take this oportunity to ask that SOMEONE take all of the known
>patches (obviously including this Y2K patch) and roll them into the main
>release, perhaps calling it 4.1 or maybe even 4.0PL3.
Ummm, there is already a beta release on hylafax.org under the main source
code directory. As soon as possible i will release an update with this patch.
PS This is almost a classic case why you should never use #defines in C++
unless absolutely necesary, much better to use a typesafe inline member
function.
- Robert
Index: AtSyntax.c++
===================================================================
RCS file: /usr/local/cvsroot/hylafax/util/AtSyntax.c++,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 AtSyntax.c++
*** AtSyntax.c++ 1998/10/12 20:47:48 1.1.1.1
--- AtSyntax.c++ 1999/05/15 06:54:02
***************
*** 38,44 ****
#define HALFDAY (12 * HOUR) // half a day (12 hours)
#define FULLDAY (24 * HOUR) // a full day (24 hours)
! #define isLeapYear(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
#ifdef streq
#undef streq
--- 38,48 ----
#define HALFDAY (12 * HOUR) // half a day (12 hours)
#define FULLDAY (24 * HOUR) // a full day (24 hours)
! static int
! isLeapYear(const tm& at) {
! int y = at.tm_year + TM_YEAR_BASE;
! return ((y % 4) == 0 && (y % 100) != 0 || (y % 400) == 0);
! }
#ifdef streq
#undef streq
***************
*** 295,301 ****
adjustYDay(struct tm& t)
{
// adjust year day according to month
! const u_int* days = daysInMonth[isLeapYear(t.tm_year)];
t.tm_yday = t.tm_mday;
for (u_int i = 0; i < t.tm_mon; i++)
t.tm_yday += days[i];
--- 299,305 ----
adjustYDay(struct tm& t)
{
// adjust year day according to month
! const u_int* days = daysInMonth[isLeapYear(t)];
t.tm_yday = t.tm_mday;
for (u_int i = 0; i < t.tm_mon; i++)
t.tm_yday += days[i];
***************
*** 344,350 ****
adjustYDay(at);
}
}
! const u_int* days = daysInMonth[isLeapYear(at.tm_year)];
if (at.tm_mday > days[at.tm_mon]) {
_atError(emsg, "Invalid day of month, %s has only %u days",
months[at.tm_mon], days[at.tm_mon]);
--- 348,354 ----
adjustYDay(at);
}
}
! const u_int* days = daysInMonth[isLeapYear(at)];
if (at.tm_mday > days[at.tm_mon]) {
_atError(emsg, "Invalid day of month, %s has only %u days",
months[at.tm_mon], days[at.tm_mon]);
***************
*** 412,418 ****
fxBool leap;
int daysinyear;
for (;;) {
! leap = isLeapYear(at.tm_year);
daysinyear = leap ? 366 : 365;
if (at.tm_yday < daysinyear)
break;
--- 416,422 ----
fxBool leap;
int daysinyear;
for (;;) {
! leap = isLeapYear(at);
daysinyear = leap ? 366 : 365;
if (at.tm_yday < daysinyear)
break;
***************
*** 429,436 ****
at.tm_mday++; // NB: [1..31]
int eday = at.tm_yday;
! for (u_int year = EPOCH_YEAR - TM_YEAR_BASE; year < at.tm_year; year++)
! eday += isLeapYear(year) ? 366 : 365;
at.tm_wday = (EPOCH_WDAY + eday) % DAYSPERWEEK;
}
--- 433,444 ----
at.tm_mday++; // NB: [1..31]
int eday = at.tm_yday;
! tm temp;
! temp.tm_year = EPOCH_YEAR - TM_YEAR_BASE;
! while (temp.tm_year < at.tm_year) {
! eday += isLeapYear(temp) ? 366 : 365;
! temp.tm_year++;
! }
at.tm_wday = (EPOCH_WDAY + eday) % DAYSPERWEEK;
}