From: Fletcher T. Penney Date: Fri, 2 Jun 2017 22:50:12 +0000 (-0400) Subject: FIXED: Silence a few warnings X-Git-Tag: 6.1.0^2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd73308bb53ede2d13c3a8d1e12ee851aef2602f;p=multimarkdown FIXED: Silence a few warnings --- diff --git a/Sources/libMultiMarkdown/aho-corasick.c b/Sources/libMultiMarkdown/aho-corasick.c index fb3255f..44cedec 100644 --- a/Sources/libMultiMarkdown/aho-corasick.c +++ b/Sources/libMultiMarkdown/aho-corasick.c @@ -414,17 +414,20 @@ match * ac_trie_search(trie * a, const char * source, size_t start, size_t len) void match_excise(match * m) { - if (m->prev) { - m->prev->next = m->next; - } + if (m) { + if (m->prev) { + m->prev->next = m->next; + } - if (m->next) { - m->next->prev = m->prev; - } + if (m->next) { + m->next->prev = m->prev; + } - free(m); + free(m); + } } + int match_count(match * m) { int result = 0; m = m->next; // Skip header diff --git a/Sources/libMultiMarkdown/epub.c b/Sources/libMultiMarkdown/epub.c index 1dc79a1..66a27ec 100644 --- a/Sources/libMultiMarkdown/epub.c +++ b/Sources/libMultiMarkdown/epub.c @@ -306,6 +306,10 @@ bool add_asset_from_file(mz_zip_archive * pZip, asset * a, const char * destinat if (buffer && buffer->currentStringLength > 0) { status = mz_zip_writer_add_mem(pZip, destination, buffer->str, buffer->currentStringLength, MZ_BEST_COMPRESSION); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } + d_string_free(buffer, true); result = true; } @@ -351,7 +355,10 @@ void add_assets(mz_zip_archive * pZip, mmd_engine * e, const char * directory) { if (e->asset_hash){ CURL * curl; CURLcode res; + struct MemoryStruct chunk; + chunk.memory = malloc(1); + chunk.size = 0; char destination[100] = "OEBPS/assets/"; destination[49] = '\0'; @@ -366,9 +373,6 @@ void add_assets(mz_zip_archive * pZip, mmd_engine * e, const char * directory) { curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); HASH_ITER(hh, e->asset_hash, a, a_tmp) { - chunk.memory = malloc(1); - chunk.size = 0; - curl_easy_setopt(curl, CURLOPT_URL, a->url); res = curl_easy_perform(curl); @@ -382,6 +386,10 @@ void add_assets(mz_zip_archive * pZip, mmd_engine * e, const char * directory) { } else { // Store downloaded file in zip status = mz_zip_writer_add_mem(pZip, destination, chunk.memory, chunk.size, MZ_BEST_COMPRESSION); + + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } } } } @@ -447,32 +455,54 @@ DString * epub_create(const char * body, mmd_engine * e, const char * directory) len = strlen(data); status = mz_zip_writer_add_mem(&zip, "mimetype", data, len, MZ_BEST_COMPRESSION); free(data); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Create directories status = mz_zip_writer_add_mem(&zip, "OEBPS/", NULL, 0, MZ_BEST_COMPRESSION); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } + status = mz_zip_writer_add_mem(&zip, "META-INF/", NULL, 0, MZ_BEST_COMPRESSION); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Add container data = epub_container_xml(); len = strlen(data); status = mz_zip_writer_add_mem(&zip, "META-INF/container.xml", data, len, MZ_BEST_COMPRESSION); free(data); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Add package data = epub_package_document(scratch); len = strlen(data); status = mz_zip_writer_add_mem(&zip, "OEBPS/main.opf", data, len, MZ_BEST_COMPRESSION); free(data); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Add nav data = epub_nav(e, scratch); len = strlen(data); status = mz_zip_writer_add_mem(&zip, "OEBPS/nav.xhtml", data, len, MZ_BEST_COMPRESSION); free(data); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Add main document len = strlen(body); status = mz_zip_writer_add_mem(&zip, "OEBPS/main.xhtml", body, len, MZ_BEST_COMPRESSION); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } // Add assets add_assets(&zip, e, directory); @@ -483,6 +513,9 @@ DString * epub_create(const char * body, mmd_engine * e, const char * directory) free(result->str); status = mz_zip_writer_finalize_heap_archive(&zip, (void **) &(result->str), &(result->currentStringLength)); + if (!status) { + fprintf(stderr, "Error adding asset to zip.\n"); + } return result; } diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index bc6355a..d611d88 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -259,7 +259,7 @@ void mmd_export_link_html(DString * out, const char * source, token * text, link text->child->next->len++; } - if (text->child) + if (text && text->child) mmd_export_token_tree_html(out, source, text->child, scratch); print_const(""); diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index d9d59bb..123e0d9 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1955,7 +1955,9 @@ bool mmd_d_string_has_metadata(DString * source, size_t * end) { /// Does the text have metadata? bool mmd_engine_has_metadata(mmd_engine * e, size_t * end) { bool result = false; - + if (!e || !end) + return false; + if (!(scan_meta_line(&e->dstr->str[0]))) { // First line is not metadata, so can't have metadata // Saves the time of an unnecessary parse diff --git a/Sources/libMultiMarkdown/token.c b/Sources/libMultiMarkdown/token.c index a1a1b50..77582ba 100644 --- a/Sources/libMultiMarkdown/token.c +++ b/Sources/libMultiMarkdown/token.c @@ -320,7 +320,6 @@ token * token_prune_graft(token * first, token * last, unsigned short container_ if (first == NULL || last == NULL) return first; - token * prev = first->prev; token * next = last->next; // Duplicate first token -- this will be child of new container diff --git a/Sources/libMultiMarkdown/writer.c b/Sources/libMultiMarkdown/writer.c index d57eecf..89dd314 100644 --- a/Sources/libMultiMarkdown/writer.c +++ b/Sources/libMultiMarkdown/writer.c @@ -1033,6 +1033,8 @@ footnote * footnote_new(const char * source, token * label, token * content, boo f->free_para = true; break; } + } else { + f->content = NULL; } } @@ -2205,7 +2207,8 @@ void abbreviation_from_bracket(const char * source, scratch_pad * scratch, token // Adjust the properties free(temp->label_text); temp->label_text = temp->clean_text; - temp->clean_text = clean_string_from_range(source, temp->content->child->start, t->start + t->len - t->child->mate->len - temp->content->child->start, false); + if (temp->content && temp->content->child) + temp->clean_text = clean_string_from_range(source, temp->content->child->start, t->start + t->len - t->child->mate->len - temp->content->child->start, false); // Store as used stack_push(scratch->used_abbreviations, temp);