diff --git a/css.c b/css.c index 7f2b00a..3eb30b3 100644 --- a/css.c +++ b/css.c @@ -48,17 +48,22 @@ mkd_css(Document *d, char **res) int size; if ( res && d && d->compiled ) { + *res = 0; CREATE(f); RESERVE(f, 100); stylesheets(d->code, &f); - if ( (size = S(f)) > 0 ) + if ( (size = S(f)) > 0 ) { EXPAND(f) = 0; /* HACK ALERT! HACK ALERT! HACK ALERT! */ - *res = T(f); /* we know that a T(Cstring) is a character pointer */ + *res = T(f);/* we know that a T(Cstring) is a character pointer */ /* so we can simply pick it up and carry it away, */ - return size; /* leaving the husk of the Ctring on the stack */ + /* leaving the husk of the Ctring on the stack */ /* END HACK ALERT */ + } + else + DELETE(f); + return size; } return EOF; } diff --git a/toc.c b/toc.c index 0948ccd..f790614 100644 --- a/toc.c +++ b/toc.c @@ -24,9 +24,10 @@ mkd_toc(Document *p, char **doc) Cstring res; int size; - *doc = 0; + if ( !(doc && p && p->ctx) ) return -1; - if ( !(p && p->ctx) ) return -1; + *doc = 0; + if ( ! (p->ctx->flags & MKD_TOC) ) return 0; CREATE(res); @@ -67,14 +68,17 @@ mkd_toc(Document *p, char **doc) Csprintf(&res, last_hnumber ? "%*s\n" : "%*s\n", last_hnumber, ""); } - if ( (size = S(res)) > 0 ) + if ( (size = S(res)) > 0 ) { EXPAND(res) = 0; /* HACK ALERT! HACK ALERT! HACK ALERT! */ - *doc = T(res); /* we know that a T(Cstring) is a character pointer + *doc = T(res); /* we know that a T(Cstring) is a character pointer * so we can simply pick it up and carry it away, * leaving the husk of the Ctring on the stack * END HACK ALERT */ + } + else + DELETE(res); return size; } @@ -89,9 +93,9 @@ mkd_generatetoc(Document *p, FILE *out) int ret = EOF; if ( sz > 0 ) - ret = fwrite(buf, sz, 1, out); + ret = fwrite(buf, 1, sz, out); if ( buf ) free(buf); - return ret; + return (ret == sz) ? ret : EOF; }