summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-13 17:07:41 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-13 17:39:44 +0100
commit56f615ffe26c6fcb47333697d1dad687290c8ba9 (patch)
tree6cbb0ebb6fce4c6450ccd0d26bd6a2cbee2e7338
parent5f344e177fd9d6f4ed19068af009f583abb46b78 (diff)
downloadcalcurse-56f615ffe26c6fcb47333697d1dad687290c8ba9.tar.gz
calcurse-56f615ffe26c6fcb47333697d1dad687290c8ba9.zip
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>
-rw-r--r--src/ical.c32
1 files changed, 10 insertions, 22 deletions
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