RSSClient: actualy use the precalculated length for the StrBuf allocation
[citadel.git] / citadel / modules / rssclient / rss_atom_parser.c
index 0c7290b5cc0857ce856d43a2ce614ca2eedb11aa..86346296244eb3504d1f7b5bccaa532b9b805a50 100644 (file)
@@ -745,7 +745,7 @@ void rss_save_item(rss_item *ri, rss_aggregator *RSSAggr)
                len = StrLength(ri->title);
                Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
                len = strlen(Sbj);
-               if (Sbj[len - 1] == '\n')
+               if ((len > 0) && (Sbj[len - 1] == '\n'))
                {
                        len --;
                        Sbj[len] = '\0';
@@ -777,7 +777,7 @@ void rss_save_item(rss_item *ri, rss_aggregator *RSSAggr)
 
        msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
 
-       Message = NewStrBufPlain(NULL, StrLength(ri->description));
+       Message = NewStrBufPlain(NULL, msglen);
 
        StrBufPlain(Message, HKEY(
                            "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
@@ -1086,9 +1086,9 @@ void rss_parser_cleanup(void)
        DeleteHash(&KnownNameSpaces);
 }
 
-void LogDebugEnableRSSATOMParser(void)
+void LogDebugEnableRSSATOMParser(const int n)
 {
-       RSSAtomParserDebugEnabled = 1;
+       RSSAtomParserDebugEnabled = n;
 }
 
 CTDL_MODULE_INIT(rssparser)
@@ -1177,7 +1177,7 @@ CTDL_MODULE_INIT(rssparser)
                /* we don't like these namespaces because of they shadow our usefull parameters. */
                Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);
 #endif
-               CtdlRegisterDebugFlagHook(HKEY("RSSAtomParser"), LogDebugEnableRSSATOMParser);
+               CtdlRegisterDebugFlagHook(HKEY("RSSAtomParser"), LogDebugEnableRSSATOMParser, &RSSAtomParserDebugEnabled);
                CtdlRegisterCleanupHook(rss_parser_cleanup);
        }
        return "rssparser";