]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Silence a few warnings
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 2 Jun 2017 22:50:12 +0000 (18:50 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 2 Jun 2017 22:50:12 +0000 (18:50 -0400)
Sources/libMultiMarkdown/aho-corasick.c
Sources/libMultiMarkdown/epub.c
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/mmd.c
Sources/libMultiMarkdown/token.c
Sources/libMultiMarkdown/writer.c

index fb3255f602ea452cf2830c234c836e791b51a5a1..44cedec10f6c511914ac4ef5dad469d1b42084b7 100644 (file)
@@ -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
index 1dc79a156c270457610f8f66f758febf4a0771c2..66a27ec20f021737072993c55643c60173dd4fb0 100644 (file)
@@ -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;
 }
index bc6355a73e8b36160b735145c25550413275f3bf..d611d882d789834e24cbe0f2de987cebf8b71d97 100644 (file)
@@ -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("</a>");
index d9d59bb812c164707367cb0f29703218a22cdb74..123e0d97140ddf3764769a31e532e6cbe1c20dfa 100644 (file)
@@ -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 
index a1a1b50860e71a6246c3b39ff7656e27b3ff2d19..77582ba64bdbb29deae7da1c78687a3b8e64c381 100644 (file)
@@ -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
index d57eecf3f094ef30683ae4d578d1c73b4d34c5b6..89dd31418854296d6880d4b9ea4031808ab963f9 100644 (file)
@@ -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);