Commit e8285942202a0a662f21f288eda2219fe8ca9f44

Kai Koehne 2021-06-14T09:47:17

Fix MSVC compiler level 3 warnings (#162) Fix various C4244 warnings with the MSVC compiler for 64 bit

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57e353f..cab797e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ if(${CMAKE_C_COMPILER_ID} MATCHES GNU|Clang)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
 elseif(MSVC)
     # Disable warnings about the so-called unsecured functions:
-    add_definitions(/D_CRT_SECURE_NO_WARNINGS)
+    add_definitions(/D_CRT_SECURE_NO_WARNINGS /W3)
 
     # Specify proper C runtime library:
     string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
diff --git a/md2html/md2html.c b/md2html/md2html.c
index 1758b0b..40bc68f 100644
--- a/md2html/md2html.c
+++ b/md2html/md2html.c
@@ -114,7 +114,7 @@ process_output(const MD_CHAR* text, MD_SIZE size, void* userdata)
 static int
 process_file(FILE* in, FILE* out)
 {
-    MD_SIZE n;
+    size_t n;
     struct membuffer buf_in = {0};
     struct membuffer buf_out = {0};
     int ret = -1;
@@ -135,13 +135,13 @@ process_file(FILE* in, FILE* out)
 
     /* Input size is good estimation of output size. Add some more reserve to
      * deal with the HTML header/footer and tags. */
-    membuf_init(&buf_out, buf_in.size + buf_in.size/8 + 64);
+    membuf_init(&buf_out, (MD_SIZE)(buf_in.size + buf_in.size/8 + 64));
 
     /* Parse the document. This shall call our callbacks provided via the
      * md_renderer_t structure. */
     t0 = clock();
 
-    ret = md_html(buf_in.data, buf_in.size, process_output, (void*) &buf_out,
+    ret = md_html(buf_in.data, (MD_SIZE)buf_in.size, process_output, (void*) &buf_out,
                     parser_flags, renderer_flags);
 
     t1 = clock();
diff --git a/src/md4c-html.c b/src/md4c-html.c
index eb60eaa..22907f1 100644
--- a/src/md4c-html.c
+++ b/src/md4c-html.c
@@ -195,7 +195,7 @@ render_utf8_codepoint(MD_HTML* r, unsigned codepoint,
     }
 
     if(0 < codepoint  &&  codepoint <= 0x10ffff)
-        fn_append(r, (char*)utf8, n);
+        fn_append(r, (char*)utf8, (MD_SIZE)n);
     else
         fn_append(r, utf8_replacement_char, 3);
 }
diff --git a/src/md4c.c b/src/md4c.c
index 6aeef11..d30a50c 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -916,7 +916,7 @@ md_merge_lines(MD_CTX* ctx, OFF beg, OFF end, const MD_LINE* lines, int n_lines,
         }
 
         if(off >= end) {
-            *p_size = ptr - buffer;
+            *p_size = (MD_SIZE)(ptr - buffer);
             return;
         }
 
@@ -2229,7 +2229,7 @@ md_is_link_reference(MD_CTX* ctx, const MD_LINE* lines, int n_lines,
 
     if(beg_line != end_line) {
         MD_CHECK(md_merge_lines_alloc(ctx, beg, end, beg_line,
-                 n_lines - (beg_line - lines), _T(' '), &label, &label_size));
+                 (int)(n_lines - (beg_line - lines)), _T(' '), &label, &label_size));
     } else {
         label = (CHAR*) STR(beg);
         label_size = end - beg;
@@ -4265,7 +4265,8 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
                     MD_CHECK(md_enter_leave_span_a(ctx, (mark->ch != ']'),
                                 (opener->ch == '!' ? MD_SPAN_IMG : MD_SPAN_A),
                                 STR(dest_mark->beg), dest_mark->end - dest_mark->beg, FALSE,
-                                md_mark_get_ptr(ctx, title_mark - ctx->marks), title_mark->prev));
+                                md_mark_get_ptr(ctx, (int)(title_mark - ctx->marks)),
+								title_mark->prev));
 
                     /* link/image closer may span multiple lines. */
                     if(mark->ch == ']') {
@@ -4908,7 +4909,7 @@ md_push_block_bytes(MD_CTX* ctx, int n_bytes)
 
         /* Fix the ->current_block after the reallocation. */
         if(ctx->current_block != NULL) {
-            OFF off_current_block = (char*) ctx->current_block - (char*) ctx->block_bytes;
+            OFF off_current_block = (OFF) ((char*) ctx->current_block - (char*) ctx->block_bytes);
             ctx->current_block = (MD_BLOCK*) ((char*) new_block_bytes + off_current_block);
         }