]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Fix memory bug and silence warnings
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 12 Jul 2017 17:55:46 +0000 (13:55 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 12 Jul 2017 17:55:46 +0000 (13:55 -0400)
Sources/libMultiMarkdown/epub.c
Sources/libMultiMarkdown/latex.c
Sources/libMultiMarkdown/opendocument.c
Sources/libMultiMarkdown/textbundle.c
Sources/multimarkdown/main.c

index fd5d5554b9c137fb1817160a3cf21a457858669f..5bd83026dec326133e5b6b3a13a2be421a82aece 100644 (file)
@@ -525,7 +525,7 @@ DString * epub_create(const char * body, mmd_engine * e, const char * directory)
        // Finalize zip archive and extract data
        free(result->str);
 
-       status = mz_zip_writer_finalize_heap_archive(&zip, (void **) &(result->str), &(result->currentStringLength));
+       status = mz_zip_writer_finalize_heap_archive(&zip, (void **) &(result->str), (size_t *) &(result->currentStringLength));
        if (!status) {
                fprintf(stderr, "Error adding asset to zip.\n");
        }
index e22e6dcffe6195b2c693b59b3782b7faaaf5974f..dc82880b52e5268bd00c6bf035853c2e3d3cbdb2 100644 (file)
@@ -1235,7 +1235,7 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat
                                                if (temp_char3) {
                                                        // Convert `\]\[` to `][`
                                                        temp_char[temp_char3 - temp_char] = ']';
-                                                       memmove(temp_char3 + 1, temp_char3 + 3, strlen(temp_char3 - 3));
+                                                       memmove(temp_char3 + 1, temp_char3 + 3, strlen(temp_char3) - 2);
                                                }
 
                                                if (temp_bool) {
index b6368febfe67816e601e00bfcc6a966c4430e229..725797bb29bc7fd3637eb77da2aad5da26d30b8b 100644 (file)
@@ -944,7 +944,7 @@ DString * opendocument_core_file_create(const char * body, mmd_engine * e, const
        // Clean up
        free(result->str);
 
-       status = mz_zip_writer_finalize_heap_archive(zip, (void **) &(result->str), &(result->currentStringLength));
+       status = mz_zip_writer_finalize_heap_archive(zip, (void **) &(result->str), (size_t *) &(result->currentStringLength));
        if (!status) {
                fprintf(stderr, "Error finalizing zip archive.\n");
        }
index b8a0157ffc051ed767f7479798c1d6388303b140..b401bc90b17fc3fc4dd2629b071044bd2659ba90 100644 (file)
@@ -412,7 +412,7 @@ DString * textbundle_create(const char * body, mmd_engine * e, const char * dire
        // Finalize zip archive and extract data
        free(result->str);
 
-       status = mz_zip_writer_finalize_heap_archive(&zip, (void **) &(result->str), &(result->currentStringLength));
+       status = mz_zip_writer_finalize_heap_archive(&zip, (void **) &(result->str), (size_t *) &(result->currentStringLength));
        if (!status) {
                fprintf(stderr, "Error finalizing zip.\n");
        }
index 60bc180f46e4a3826451dee191af917c340a758f..7b6bac41114b034e40abc9fe09054f8c7510639f 100644 (file)
@@ -81,6 +81,18 @@ struct arg_end *a_end;
 struct arg_rem *a_rem1, *a_rem2, *a_rem3, *a_rem4, *a_rem5, *a_rem6;
 
 
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+       char * result = malloc(strlen(source) + 1);
+
+       if (result) {
+               strcpy(result, source);
+       }
+
+       return result;
+}
+
+
 DString * stdin_buffer() {
        /* Read from stdin and return a DString *
                `buffer` will need to be freed elsewhere */
@@ -107,7 +119,7 @@ char * filename_with_extension(const char * original, const char * new_extension
        DString * new_name;
 
        // Determine output filename without file extension
-       name_no_ext = strdup(original);
+       name_no_ext = my_strdup(original);
 
        if (strrchr(name_no_ext, '.') != NULL) {
                long count = strrchr(name_no_ext, '.') - name_no_ext;