diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2013-05-20 19:57:36 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2013-05-20 19:57:36 +0200 |
commit | b9cd5fc07be60f69f3b03ec2707389672cb83ca6 (patch) | |
tree | a46652827e30b0d8e9274e2e7ea8026b9e55969a | |
parent | 50ee652bb20e5daed443703ab0d33c4b3c9f0fb9 (diff) |
sfeed_opml_import: dont use dynamic allocation, assumes sane lengths and just use a static buffer
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
-rw-r--r-- | sfeed_opml_import.c | 36 |
1 files 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 <name> <url> [encoding]\n", stdout); xmlparser_parse(&parser); fputs("}\n", stdout); - - free(feedurl); - free(feedname); - free(basesiteurl); - return EXIT_SUCCESS; } |