From 56f615ffe26c6fcb47333697d1dad687290c8ba9 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Wed, 13 Jan 2016 17:07:41 +0100
Subject: Reimplement ical_unformat_line() using dynamic strings

Use the new dynamic string utility functions instead of relying on a
fixed-size buffer.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/ical.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

(limited to 'src')

diff --git a/src/ical.c b/src/ical.c
index 3d9a712..b87f0e5 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -387,55 +387,43 @@ ical_store_apoint(char *mesg, char *note, long start, long dur,
 /*
  * Returns an allocated string representing the string given in argument once
  * unformatted.
- *
- * Note:
- * Even if the RFC2445 recommends not to have more than 75 octets on one line of
- * text, I prefer not to restrict the parsing to this size, thus I use a buffer
- * of size BUFSIZ.
- *
- * Extract from RFC2445:
- * Lines of text SHOULD NOT be longer than 75 octets, excluding the line
- * break.
  */
 static char *ical_unformat_line(char *line)
 {
-	char *p, uline[BUFSIZ];
-	int len;
-
-	if (strlen(line) >= BUFSIZ)
-		return NULL;
+	struct string s;
+	char *p;
 
-	memset(uline, 0, BUFSIZ);
-	for (len = 0, p = line; *p; p++) {
+	string_init(&s);
+	for (p = line; *p; p++) {
 		switch (*p) {
 		case '\\':
 			switch (*(p + 1)) {
 			case 'n':
-				uline[len++] = '\n';
+				string_catf(&s, "%c", '\n');
 				p++;
 				break;
 			case 't':
-				uline[len++] = '\t';
+				string_catf(&s, "%c", '\t');
 				p++;
 				break;
 			case ';':
 			case ':':
 			case ',':
-				uline[len++] = *(p + 1);
+				string_catf(&s, "%c", *(p + 1));
 				p++;
 				break;
 			default:
-				uline[len++] = *p;
+				string_catf(&s, "%c", *p);
 				break;
 			}
 			break;
 		default:
-			uline[len++] = *p;
+			string_catf(&s, "%c", *p);
 			break;
 		}
 	}
 
-	return mem_strdup(uline);
+	return string_buf(&s);
 }
 
 static void
-- 
cgit v1.2.3-70-g09d2