sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 502d03d4f3047bdbe7f223354f851b28e16167fd
parent 029bb88fc7244b2281b1a26b19d34c4e2ea12769
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 28 Feb 2016 17:34:45 +0100

null-terminate line at newline from getline()

Diffstat:
Msfeed_frames.c | 6++++--
Msfeed_html.c | 5++++-
Msfeed_mbox.c | 2++
Msfeed_plain.c | 6+++++-
4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -104,7 +104,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) { char dirpath[PATH_MAX], filepath[PATH_MAX]; char *fields[FieldLast], *feedname, name[128]; - size_t namelen; + ssize_t linelen; struct stat st; FILE *fpcontent = NULL; unsigned int isnew; @@ -138,7 +138,9 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", fpitems); - while (getline(&line, &linesize, fpin) > 0) { + while ((linelen = getline(&line, &linesize, fpin)) > 0) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; if (!parseline(line, fields)) break; /* write content */ diff --git a/sfeed_html.c b/sfeed_html.c @@ -19,6 +19,7 @@ printfeed(FILE *fp, struct feed *f) char *fields[FieldLast]; time_t parsedtime; unsigned int islink, isnew; + ssize_t linelen; if (f->name[0] != '\0') { fputs("<h2 id=\"", stdout); @@ -31,7 +32,9 @@ printfeed(FILE *fp, struct feed *f) } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", stdout); - while (getline(&line, &linesize, fp) > 0) { + while ((linelen = getline(&line, &linesize, fp)) > 0) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; if (!parseline(line, fields)) break; parsedtime = 0; diff --git a/sfeed_mbox.c b/sfeed_mbox.c @@ -67,6 +67,8 @@ printfeed(FILE *fp, const char *feedname) ssize_t linelen; while ((linelen = getline(&line, &linesize, fp)) > 0) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; if (!parseline(line, fields)) break; parsedtime = 0; diff --git a/sfeed_plain.c b/sfeed_plain.c @@ -16,10 +16,14 @@ printfeed(FILE *fp, const char *feedname) { char *fields[FieldLast]; time_t parsedtime; + ssize_t linelen; - while (getline(&line, &linesize, fp) > 0) { + while ((linelen = getline(&line, &linesize, fp)) > 0) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; if (!parseline(line, fields)) break; + parsedtime = 0; strtotime(fields[FieldUnixTimestamp], &parsedtime);