* In the calendar code, changed all "struct tm *" to "struct tm" and changed
authorArt Cancro <ajc@citadel.org>
Wed, 18 Dec 2002 05:03:39 +0000 (05:03 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 18 Dec 2002 05:03:39 +0000 (05:03 +0000)
  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.

webcit/ChangeLog
webcit/calendar_tools.c
webcit/calendar_view.c

index f6fcfef259ee91911ff6b7ad9101d78c0091ccfb..f36f481d147139c666fe3f69e773846d3422e0a6 100644 (file)
@@ -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 <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 1753a483c96bf3c5e28818581577a987f538bc14..9426716b355a21eb21bb8e74f8947c9d775a8703 100644 (file)
@@ -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("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=11; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
-                       ((tm->tm_mon == i) ? "SELECTED" : ""),
+                       ((tm.tm_mon == i) ? "SELECTED" : ""),
                        i+1,
                        months[i]
                );
@@ -98,7 +98,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
        for (i=1; i<=31; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\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("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=23; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
-                       ((tm->tm_hour == i) ? "SELECTED" : ""),
+                       ((tm.tm_hour == i) ? "SELECTED" : ""),
                        i, hourname[i]
                );
        }
@@ -136,7 +136,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=59; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
-                       ((tm->tm_min == i) ? "SELECTED" : ""),
+                       ((tm.tm_min == i) ? "SELECTED" : ""),
                        i, i
                );
        }
index 02c9f5ecb784ab02c57808e17dd0637205d8ff2e..db55d9d4758b9430a6b1fbb31d53f79363b1f5e6 100644 (file)
@@ -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("<TD><CENTER><H3>");
 
-       tm = localtime(&previous_month);
+       memcpy(&tm, localtime(&previous_month), sizeof(struct tm));
        wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
-               (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+               (int)(tm.tm_year)+1900, tm.tm_mon + 1);
        wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
 
        wprintf("&nbsp;&nbsp;"
@@ -170,9 +170,9 @@ void calendar_month_view(int year, int month, int day) {
                "</FONT>"
                "&nbsp;&nbsp;", months[month-1], year);
 
-       tm = localtime(&next_month);
+       memcpy(&tm, localtime(&next_month), sizeof(struct tm));
        wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
-               (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+               (int)(tm.tm_year)+1900, tm.tm_mon + 1);
        wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
 
        wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
@@ -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("<TR>");
                }
 
                wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
-                       ((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("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
                        "%d</A></B><BR>",
-                       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("</TD>");
 
-               if (tm->tm_wday == 6) {
+               /* After displaying Saturday, end the row */
+               if ((i % 7) == 6) {
                        wprintf("</TR>\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"));