From: Art Cancro Date: Wed, 18 Dec 2002 05:03:39 +0000 (+0000) Subject: * In the calendar code, changed all "struct tm *" to "struct tm" and changed X-Git-Tag: v7.86~6077 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=0815d0efe22b13e16222e8f22acde8fffdcbd737 * In the calendar code, changed all "struct tm *" to "struct tm" and changed all "tm = localtime(foo)" to "memcpy(&tm, localtime(foo), sizeof(struct tm))" Because the libc-allocated buffer was getting clobbered. * This fixes the problem fleeb reported with Feb 1 events making it go nuts. --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index f6fcfef25..f36f481d1 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,10 @@ $Log$ +Revision 400.66 2002/12/18 05:03:39 ajc +* In the calendar code, changed all "struct tm *" to "struct tm" and changed + all "tm = localtime(foo)" to "memcpy(&tm, localtime(foo), sizeof(struct tm))" + Because the libc-allocated buffer was getting clobbered. +* This fixes the problem fleeb reported with Feb 1 events making it go nuts. + Revision 400.65 2002/12/17 05:01:39 ajc * Prettied up the calendar day view layout * Hour/minute editing fields now use am/pm hours and 2-digit minutes @@ -1177,4 +1183,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index 1753a483c..9426716b3 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -67,27 +67,27 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { int i; time_t now; - struct tm *tm_now; + struct tm tm_now; int this_year; time_t tt; - struct tm *tm; + struct tm tm; const int span = 10; now = time(NULL); - tm_now = localtime(&now); - this_year = tm_now->tm_year + 1900; + memcpy(&tm_now, localtime(&now), sizeof(struct tm)); + this_year = tm_now.tm_year + 1900; if (t == NULL) return; tt = icaltime_as_timet(*t); - tm = localtime(&tt); + memcpy(&tm, localtime(&tt), sizeof(struct tm)); wprintf("Month: "); wprintf("\n", prefix); for (i=1; i<=31; ++i) { wprintf("\n", - ((tm->tm_mday == i) ? "SELECTED" : ""), + ((tm.tm_mday == i) ? "SELECTED" : ""), i, i ); } @@ -126,7 +126,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { wprintf("\n", prefix); for (i=0; i<=59; ++i) { wprintf("\n", - ((tm->tm_min == i) ? "SELECTED" : ""), + ((tm.tm_min == i) ? "SELECTED" : ""), i, i ); } diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 02c9f5ecb..db55d9d47 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -112,7 +112,7 @@ void calendar_month_view_display_events(time_t thetime) { void calendar_month_view(int year, int month, int day) { struct tm starting_tm; - struct tm *tm; + struct tm tm; time_t thetime; int i; time_t previous_month; @@ -127,10 +127,10 @@ void calendar_month_view(int year, int month, int day) { starting_tm.tm_mday = day; thetime = mktime(&starting_tm); - tm = &starting_tm; - while (tm->tm_mday != 1) { + memcpy(&tm, &starting_tm, sizeof(struct tm)); + while (tm.tm_mday != 1) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - tm = localtime(&thetime); + memcpy(&tm, localtime(&thetime), sizeof(struct tm)); } /* Determine previous and next months ... for links */ @@ -138,10 +138,10 @@ void calendar_month_view(int year, int month, int day) { next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */ /* Now back up until we're on a Sunday */ - tm = localtime(&thetime); - while (tm->tm_wday != 0) { + memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + while (tm.tm_wday != 0) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - tm = localtime(&thetime); + memcpy(&tm, localtime(&thetime), sizeof(struct tm)); } /* Outer table (to get the background color) */ @@ -159,9 +159,9 @@ void calendar_month_view(int year, int month, int day) { wprintf("

"); - tm = localtime(&previous_month); + memcpy(&tm, localtime(&previous_month), sizeof(struct tm)); wprintf("", - (int)(tm->tm_year)+1900, tm->tm_mon + 1); + (int)(tm.tm_year)+1900, tm.tm_mon + 1); wprintf("\n"); wprintf("  " @@ -170,9 +170,9 @@ void calendar_month_view(int year, int month, int day) { "" "  ", months[month-1], year); - tm = localtime(&next_month); + memcpy(&tm, localtime(&next_month), sizeof(struct tm)); wprintf("", - (int)(tm->tm_year)+1900, tm->tm_mon + 1); + (int)(tm.tm_year)+1900, tm.tm_mon + 1); wprintf("\n"); wprintf("

" @@ -188,32 +188,35 @@ void calendar_month_view(int year, int month, int day) { /* Now do 35 days */ for (i = 0; i < 35; ++i) { - tm = localtime(&thetime); - if (tm->tm_wday == 0) { + memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + + /* Before displaying Sunday, start a new row */ + if ((i % 7) == 0) { wprintf(""); } wprintf("", - ((tm->tm_mon != month-1) ? "DDDDDD" : - ((tm->tm_wday==0 || tm->tm_wday==6) ? "EEEECC" : + ((tm.tm_mon != month-1) ? "DDDDDD" : + ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" : "FFFFFF")) ); - if ((i==0) || (tm->tm_mday == 1)) { - wprintf("%s ", months[tm->tm_mon]); + if ((i==0) || (tm.tm_mday == 1)) { + wprintf("%s ", months[tm.tm_mon]); } wprintf("" "%d
", - tm->tm_year + 1900, - tm->tm_mon + 1, - tm->tm_mday, - tm->tm_mday); + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_mday); /* put the data here, stupid */ calendar_month_view_display_events(thetime); wprintf(""); - if (tm->tm_wday == 6) { + /* After displaying Saturday, end the row */ + if ((i % 7) == 6) { wprintf("\n"); } @@ -435,16 +438,16 @@ void calendar_day_view(int year, int month, int day) { void do_calendar_view(void) { int i; time_t now; - struct tm *tm; + struct tm tm; int year, month, day; char calview[SIZ]; /* In case no date was specified, go with today */ now = time(NULL); - tm = localtime(&now); - year = tm->tm_year + 1900; - month = tm->tm_mon + 1; - day = tm->tm_mday; + memcpy(&tm, localtime(&now), sizeof(struct tm)); + year = tm.tm_year + 1900; + month = tm.tm_mon + 1; + day = tm.tm_mday; /* Now see if a date was specified */ if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));