Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Feb 2010 07:20:26 +0000 (UTC)
From:      Edwin Groothuis <edwin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r204192 - user/edwin/calendar
Message-ID:  <201002220720.o1M7KQX8073782@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: edwin
Date: Mon Feb 22 07:20:26 2010
New Revision: 204192
URL: http://svn.freebsd.org/changeset/base/204192

Log:
  Properly limit the amount of repeats of an occurance (i.e. don't segfault)

Modified:
  user/edwin/calendar/calendar.h
  user/edwin/calendar/events.c
  user/edwin/calendar/io.c
  user/edwin/calendar/parsedata.c

Modified: user/edwin/calendar/calendar.h
==============================================================================
--- user/edwin/calendar/calendar.h	Mon Feb 22 07:19:25 2010	(r204191)
+++ user/edwin/calendar/calendar.h	Mon Feb 22 07:20:26 2010	(r204192)
@@ -95,6 +95,15 @@ extern int eastlongitude;
 #define STRING_JUNSOLSTICE	"JunSolstice"
 #define STRING_DECSOLSTICE	"DecSolstice"
 
+#define	MAXCOUNT		125	/* Random number of maximum number of
+					 * repeats of an event. Should be 52
+					 * (number of weeks per year), if you
+					 * want to show two years then it
+					 * should be 104. If you are seeing
+					 * more than this you are using this
+					 * program wrong.
+					 */
+
 /* 
  * All the astronomical calculations are carried out for the meridian 120
  * degrees east of Greenwich.

Modified: user/edwin/calendar/events.c
==============================================================================
--- user/edwin/calendar/events.c	Mon Feb 22 07:19:25 2010	(r204191)
+++ user/edwin/calendar/events.c	Mon Feb 22 07:20:26 2010	(r204192)
@@ -62,7 +62,7 @@ event_add(int year, int month, int day, 
 	if (e->text == NULL)
 		errx(1, "event_add: cannot allocate memory");
 	e->extra = NULL;
-	if (extra != NULL)
+	if (extra != NULL && extra[0] != '\0')
 		e->extra = strdup(extra);
 	addtodate(e, year, month, day);
 	return (e);

Modified: user/edwin/calendar/io.c
==============================================================================
--- user/edwin/calendar/io.c	Mon Feb 22 07:19:25 2010	(r204191)
+++ user/edwin/calendar/io.c	Mon Feb 22 07:20:26 2010	(r204192)
@@ -82,7 +82,6 @@ struct iovec header[] = {
 	{"'s Calendar\nPrecedence: bulk\n\n", 30},
 };
 
-#define MAXCOUNT	55
 #define	REPLACE(string, slen, struct_) \
 		if (strncasecmp(buf, (string), (slen)) == 0 && buf[(slen)]) { \
 			if (struct_.name != NULL)			      \

Modified: user/edwin/calendar/parsedata.c
==============================================================================
--- user/edwin/calendar/parsedata.c	Mon Feb 22 07:19:25 2010	(r204191)
+++ user/edwin/calendar/parsedata.c	Mon Feb 22 07:20:26 2010	(r204192)
@@ -298,17 +298,25 @@ allfine:
 }
 
 static void
-remember(int index, int *y, int *m, int *d, char **ed, int yy, int mm, int dd,
+remember(int *index, int *y, int *m, int *d, char **ed, int yy, int mm, int dd,
     char *extra)
 {
+	static int warned = 0;
 
-	y[index] = yy;
-	m[index] = mm;
-	d[index] = dd;
+	if (*index >= MAXCOUNT - 1) {
+		if (warned == 0)
+			warnx("Index > %d, ignored", MAXCOUNT);
+		warned++;
+		return;
+	}
+	y[*index] = yy;
+	m[*index] = mm;
+	d[*index] = dd;
 	if (extra != NULL)
-		strcpy(ed[index], extra);
+		strcpy(ed[*index], extra);
 	else
-		ed[index][0] = '\0';
+		ed[*index][0] = '\0';
+	*index += 1;
 }
 
 static void
@@ -445,7 +453,7 @@ parsedaymonth(char *date, int *yearp, in
 		if (*flags == (F_MONTH | F_DAYOFMONTH)) {
 			if (!remember_ymd(year, imonth, idayofmonth))
 				continue;
-			remember(index++, yearp, monthp, dayp, edp,
+			remember(&index, yearp, monthp, dayp, edp,
 			    year, imonth, idayofmonth, NULL);
 			continue;
 		}
@@ -455,7 +463,7 @@ parsedaymonth(char *date, int *yearp, in
 			for (m = 1; m <= 12; m++) {
 				if (!remember_ymd(year, m, idayofmonth))
 					continue;
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, m, idayofmonth, NULL);
 			}
 			continue;
@@ -466,7 +474,7 @@ parsedaymonth(char *date, int *yearp, in
 			for (d = 1; d <= yearinfo->mondays[imonth]; d++) {
 				if (!remember_ymd(year, imonth, d))
 					continue;
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, imonth, d, NULL);
 			}
 			continue;
@@ -477,7 +485,7 @@ parsedaymonth(char *date, int *yearp, in
 			for (m = 1; m <= 12; m++) {
 				if (!remember_ymd(year, m, idayofmonth))
 					continue;
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, m, idayofmonth, NULL);
 			}
 			continue;
@@ -489,7 +497,7 @@ parsedaymonth(char *date, int *yearp, in
 			d = (idayofweek - dow + 8) % 7;
 			while (d <= 366) {
 				if (remember_yd(year, d, &rm, &rd))
-					remember(index++,
+					remember(&index,
 					    yearp, monthp, dayp, edp,
 					    year, rm, rd, NULL);
 				d += 7;
@@ -508,7 +516,7 @@ parsedaymonth(char *date, int *yearp, in
 				while (d <= yearinfo->mondays[imonth]) {
 					if (--offset == 0
 					 && remember_ymd(year, imonth, d)) {
-						remember(index++,
+						remember(&index,
 						    yearp, monthp, dayp, edp,
 						    year, imonth, d, NULL);
 						continue;
@@ -525,7 +533,7 @@ parsedaymonth(char *date, int *yearp, in
 					d -= 7;
 				}
 				if (remember_ymd(year, imonth, d))
-					remember(index++,
+					remember(&index,
 					    yearp, monthp, dayp, edp,
 					    year, imonth, d, NULL);
 				continue;
@@ -539,7 +547,7 @@ parsedaymonth(char *date, int *yearp, in
 			d = (idayofweek - dow + 8) % 7;
 			while (d <= yearinfo->mondays[imonth]) {
 				if (remember_ymd(year, imonth, d))
-					remember(index++,
+					remember(&index,
 					    yearp, monthp, dayp, edp,
 					    year, imonth, d, NULL);
 				d += 7;
@@ -555,7 +563,7 @@ parsedaymonth(char *date, int *yearp, in
 				offset = parseoffset(modifieroffset);
 			if (remember_yd(year, yearinfo->ieaster + offset,
 			    &rm, &rd))
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, NULL);
 			continue;
 		}
@@ -568,7 +576,7 @@ parsedaymonth(char *date, int *yearp, in
 				offset = parseoffset(modifieroffset);
 			if (remember_yd(year, yearinfo->ipaskha + offset,
 			    &rm, &rd))
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, NULL);
 			continue;
 		}
@@ -581,7 +589,7 @@ parsedaymonth(char *date, int *yearp, in
 				offset = parseoffset(modifieroffset);
 			if (remember_yd(year, yearinfo->firstcnyday + offset,
 			    &rm, &rd))
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, NULL);
 			continue;
 		}
@@ -600,7 +608,7 @@ parsedaymonth(char *date, int *yearp, in
 					&rm, &rd)) {
 					ed = floattotime(
 					    yearinfo->ffullmoon[i]);
-					remember(index++,
+					remember(&index,
 					    yearp, monthp, dayp, edp,
 					    year, rm, rd, ed);
 				}
@@ -621,7 +629,7 @@ parsedaymonth(char *date, int *yearp, in
 				    floor(yearinfo->fnewmoon[i]) + offset,
 				    &rm, &rd)) {
 					ed = floattotime(yearinfo->fnewmoon[i]);
-					remember(index++,
+					remember(&index,
 					    yearp, monthp, dayp, edp,
 					    year, rm, rd, ed);
 				}
@@ -638,7 +646,7 @@ parsedaymonth(char *date, int *yearp, in
 			if (remember_yd(year, yearinfo->equinoxdays[0] + offset,
 			    &rm, &rd)) {
 				ed = floattotime(yearinfo->equinoxdays[0]);
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, ed);
 			}
 			continue;
@@ -651,7 +659,7 @@ parsedaymonth(char *date, int *yearp, in
 			if (remember_yd(year, yearinfo->equinoxdays[1] + offset,
 			    &rm, &rd)) {
 				ed = floattotime(yearinfo->equinoxdays[1]);
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, ed);
 			}
 			continue;
@@ -666,7 +674,7 @@ parsedaymonth(char *date, int *yearp, in
 			if (remember_yd(year,
 			    yearinfo->solsticedays[0] + offset, &rm, &rd)) {
 				ed = floattotime(yearinfo->solsticedays[0]);
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, ed);
 			}
 			continue;
@@ -679,7 +687,7 @@ parsedaymonth(char *date, int *yearp, in
 			if (remember_yd(year,
 			    yearinfo->solsticedays[1] + offset, &rm, &rd)) {
 				ed = floattotime(yearinfo->solsticedays[1]);
-				remember(index++, yearp, monthp, dayp, edp,
+				remember(&index, yearp, monthp, dayp, edp,
 				    year, rm, rd, ed);
 			}
 			continue;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002220720.o1M7KQX8073782>