From b9cd5fc07be60f69f3b03ec2707389672cb83ca6 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 20 May 2013 19:57:36 +0200 Subject: sfeed_opml_import: dont use dynamic allocation, assumes sane lengths and just use a static buffer Signed-off-by: Hiltjo Posthuma --- sfeed_opml_import.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/sfeed_opml_import.c b/sfeed_opml_import.c index 486435d..2abc472 100644 --- a/sfeed_opml_import.c +++ b/sfeed_opml_import.c @@ -7,7 +7,7 @@ #include "compat.h" XMLParser parser; /* XML parser state */ -char *feedurl = NULL, *feedname = NULL, *basesiteurl = NULL; +char feedurl[2048], feedname[2048], basesiteurl[2048]; int istag(const char *s1, const char *s2) { @@ -22,37 +22,34 @@ isattr(const char *s1, const char *s2) { void xml_handler_start_element(XMLParser *p, const char *tag, size_t taglen) { if(istag(tag, "outline")) { - feedurl = NULL; - feedname = NULL; - basesiteurl = NULL; + feedurl[0] = '\0'; + feedname[0] = '\0'; + basesiteurl[0] = '\0'; } } void xml_handler_end_element(XMLParser *p, const char *tag, size_t taglen, int isshort) { if(istag(tag, "outline")) { - printf("\tfeed \"%s\" \"%s\" \"%s\"\n", feedname ? feedname : "unnamed", - feedurl ? feedurl : "", basesiteurl ? basesiteurl : ""); + printf("\tfeed \"%s\" \"%s\" \"%s\"\n", feedname[0] ? feedname : "unnamed", + feedurl[0] ? feedurl : "", basesiteurl[0] ? basesiteurl : ""); } } void xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, const char *name, size_t namelen, const char *value, size_t valuelen) { if(istag(tag, "outline")) { - if(isattr(name, "text") || isattr(name, "title")) { - free(feedname); - feedname = xstrdup(value); - } else if(isattr(name, "htmlurl")) { - free(basesiteurl); - basesiteurl = xstrdup(value); - } else if(isattr(name, "xmlurl")) { - free(feedurl); - feedurl = xstrdup(value); - } + if(isattr(name, "text") || isattr(name, "title")) + strncpy(feedname, value, sizeof(feedname) - 1); + else if(isattr(name, "htmlurl")) + strncpy(basesiteurl, value, sizeof(basesiteurl) - 1); + else if(isattr(name, "xmlurl")) + strncpy(feedurl, value, sizeof(feedurl) - 1); } } -int main(void) { +int +main(void) { xmlparser_init(&parser); parser.xmltagstart = xml_handler_start_element; @@ -72,10 +69,5 @@ int main(void) { " # feed [encoding]\n", stdout); xmlparser_parse(&parser); fputs("}\n", stdout); - - free(feedurl); - free(feedname); - free(basesiteurl); - return EXIT_SUCCESS; } -- cgit v1.2.3