From: Michael Göhler Date: Sun, 17 Aug 2014 00:25:27 +0000 (+0200) Subject: initialize all variables correctly + make it finally work X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=882cc804087501c46d5bd96994d17214e0cad198;p=smdp.git initialize all variables correctly + make it finally work --- diff --git a/markdown.c b/markdown.c index 3cbdf0d..e578fa9 100644 --- a/markdown.c +++ b/markdown.c @@ -6,6 +6,9 @@ line_t *new_line() { line_t *x = malloc(sizeof(line_t)); + x->text = (void*)0; + x->prev = x->next = (void*)0; + x->bits = x->offset = 0; return x; } @@ -18,6 +21,8 @@ line_t *next_line(line_t *prev) { page_t *new_page() { page_t *x = malloc(sizeof(page_t)); + x->line = (void*)0; + x->prev = x->next = (void*)0; return x; } @@ -30,6 +35,8 @@ page_t *next_page(page_t *prev) { document_t *new_document() { document_t *x = malloc(sizeof(document_t)); + x->title = x->author = x->date = (void*)0; + x->page = (void*)0; return x; } diff --git a/markdown_io.c b/markdown_io.c index af04eed..58c7f3a 100644 --- a/markdown_io.c +++ b/markdown_io.c @@ -6,7 +6,7 @@ document_t *markdown_load(FILE *input) { - int c, i, bits; + int c = 0, i = 0, bits = 0; document_t *doc; page_t *page; @@ -56,9 +56,12 @@ document_t *markdown_load(FILE *input) { // calc offset line->offset = next_nonblank(text, 0); + + // new text + text = cstring_init(); } - } else if('\t') { + } else if(c == '\t') { // expand tab to spaces for (i = 0; i <= 4; i++) @@ -77,10 +80,10 @@ document_t *markdown_load(FILE *input) { } int markdown_analyse(cstring_t *text) { - int c, i, bits, - offset, eol, - equals, hashes, stars, minus, plus, - spaces, other; + int i = 0, bits = 0, + offset = 0, eol = 0, + equals = 0, hashes = 0, stars = 0, minus = 0, plus = 0, + spaces = 0, other = 0; // count leading spaces offset = next_nonblank(text, 0);