From 7baf9297f4f2e368c7c91ac76e16e88902987ec6 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Mon, 10 Aug 2015 09:45:59 -0700 Subject: Fix MSVC inline errors when cmark is included in other sources that don't have the same set of disabled warnings --- src/buffer.h | 6 +++--- src/chunk.h | 20 ++++++++++---------- src/config.h.in | 8 ++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/buffer.h b/src/buffer.h index e99db72..88b79f3 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -48,7 +48,7 @@ unsigned char *cmark_strbuf_detach(cmark_strbuf *buf); void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, const cmark_strbuf *buf); -static inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf) { +CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) { return (char *)buf->ptr; } @@ -75,14 +75,14 @@ void cmark_strbuf_unescape(cmark_strbuf *s); /* Print error and abort. */ void cmark_strbuf_overflow_err(void); -static inline bufsize_t cmark_strbuf_check_bufsize(size_t size) { +CMARK_INLINE bufsize_t cmark_strbuf_check_bufsize(size_t size) { if (size > BUFSIZE_MAX) { cmark_strbuf_overflow_err(); } return (bufsize_t)size; } -static inline bufsize_t cmark_strbuf_safe_strlen(const char *str) { +CMARK_INLINE bufsize_t cmark_strbuf_safe_strlen(const char *str) { return cmark_strbuf_check_bufsize(strlen(str)); } diff --git a/src/chunk.h b/src/chunk.h index db1bf0d..90cf568 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -16,7 +16,7 @@ typedef struct { bufsize_t alloc; // also implies a NULL-terminated string } cmark_chunk; -static inline void cmark_chunk_free(cmark_chunk *c) { +CMARK_INLINE void cmark_chunk_free(cmark_chunk *c) { if (c->alloc) free(c->data); @@ -25,7 +25,7 @@ static inline void cmark_chunk_free(cmark_chunk *c) { c->len = 0; } -static inline void cmark_chunk_ltrim(cmark_chunk *c) { +CMARK_INLINE void cmark_chunk_ltrim(cmark_chunk *c) { assert(!c->alloc); while (c->len && cmark_isspace(c->data[0])) { @@ -34,7 +34,7 @@ static inline void cmark_chunk_ltrim(cmark_chunk *c) { } } -static inline void cmark_chunk_rtrim(cmark_chunk *c) { +CMARK_INLINE void cmark_chunk_rtrim(cmark_chunk *c) { while (c->len > 0) { if (!cmark_isspace(c->data[c->len - 1])) break; @@ -43,19 +43,19 @@ static inline void cmark_chunk_rtrim(cmark_chunk *c) { } } -static inline void cmark_chunk_trim(cmark_chunk *c) { +CMARK_INLINE void cmark_chunk_trim(cmark_chunk *c) { cmark_chunk_ltrim(c); cmark_chunk_rtrim(c); } -static inline bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, +CMARK_INLINE bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, bufsize_t offset) { const unsigned char *p = (unsigned char *)memchr(ch->data + offset, c, ch->len - offset); return p ? (bufsize_t)(p - ch->data) : ch->len; } -static inline const char *cmark_chunk_to_cstr(cmark_chunk *c) { +CMARK_INLINE const char *cmark_chunk_to_cstr(cmark_chunk *c) { unsigned char *str; if (c->alloc) { @@ -74,7 +74,7 @@ static inline const char *cmark_chunk_to_cstr(cmark_chunk *c) { return (char *)str; } -static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) { +CMARK_INLINE void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) { if (c->alloc) { free(c->data); } @@ -90,19 +90,19 @@ static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) { } } -static inline cmark_chunk cmark_chunk_literal(const char *data) { +CMARK_INLINE cmark_chunk cmark_chunk_literal(const char *data) { bufsize_t len = data ? cmark_strbuf_safe_strlen(data) : 0; cmark_chunk c = {(unsigned char *)data, len, 0}; return c; } -static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, bufsize_t pos, +CMARK_INLINE cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, bufsize_t pos, bufsize_t len) { cmark_chunk c = {ch->data + pos, len, 0}; return c; } -static inline cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf) { +CMARK_INLINE cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf) { cmark_chunk c; c.len = buf->size; diff --git a/src/config.h.in b/src/config.h.in index 5294bc9..a392111 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -15,3 +15,11 @@ #else #define CMARK_ATTRIBUTE(list) #endif + +#ifndef CMARK_INLINE + #ifdef _MSC_VER + #define CMARK_INLINE __inline + #else + #define CMARK_INLINE static inline + #endif +#endif -- cgit v1.2.3 From 59bcd222c3ef1a64045e27db24ffddeb99ee29d4 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Mon, 10 Aug 2015 09:53:46 -0700 Subject: Remove need to disable MSVC warning 4800 --- src/CMakeLists.txt | 2 +- src/inlines.c | 6 +++--- src/iterator.c | 2 +- src/node.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67d7b72..ecdd016 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,7 +155,7 @@ if(MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic") endif() diff --git a/src/inlines.c b/src/inlines.c index f8a2cfc..3275ddd 100755 --- a/src/inlines.c +++ b/src/inlines.c @@ -1034,13 +1034,13 @@ static int parse_inline(subject *subj, cmark_node *parent, int options) { case '_': case '\'': case '"': - new_inl = handle_delim(subj, c, options & CMARK_OPT_SMART); + new_inl = handle_delim(subj, c, (options & CMARK_OPT_SMART) != 0); break; case '-': - new_inl = handle_hyphen(subj, options & CMARK_OPT_SMART); + new_inl = handle_hyphen(subj, (options & CMARK_OPT_SMART) != 0); break; case '.': - new_inl = handle_period(subj, options & CMARK_OPT_SMART); + new_inl = handle_period(subj, (options & CMARK_OPT_SMART) != 0); break; case '[': advance(subj); diff --git a/src/iterator.c b/src/iterator.c index 81b6f48..19dfff8 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -31,7 +31,7 @@ cmark_iter *cmark_iter_new(cmark_node *root) { void cmark_iter_free(cmark_iter *iter) { free(iter); } static bool S_is_leaf(cmark_node *node) { - return (1 << node->type) & S_leaf_mask; + return ((1 << node->type) & S_leaf_mask) != 0; } cmark_event_type cmark_iter_next(cmark_iter *iter) { diff --git a/src/node.c b/src/node.c index ad12d63..c5f4553 100644 --- a/src/node.c +++ b/src/node.c @@ -426,7 +426,7 @@ int cmark_node_set_list_tight(cmark_node *node, int tight) { } if (node->type == CMARK_NODE_LIST) { - node->as.list.tight = tight; + node->as.list.tight = tight == 1; return 1; } else { return 0; -- cgit v1.2.3 From 722bc5df7e7bde6ec865b991e500aca04c931ad5 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Mon, 10 Aug 2015 10:06:14 -0700 Subject: Remove need to disable MSVC warning 4244 --- src/CMakeLists.txt | 2 +- src/blocks.c | 2 +- src/buffer.c | 2 +- src/html.c | 4 ++-- src/utf8.c | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ecdd016..0f04351 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,7 +155,7 @@ if(MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic") endif() diff --git a/src/blocks.c b/src/blocks.c index 6d3053b..49ac273 100755 --- a/src/blocks.c +++ b/src/blocks.c @@ -774,7 +774,7 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer, container->as.code.fenced = true; container->as.code.fence_char = peek_at(&input, parser->first_nonspace); container->as.code.fence_length = matched; - container->as.code.fence_offset = parser->first_nonspace - parser->offset; + container->as.code.fence_offset = (int8_t)(parser->first_nonspace - parser->offset); container->as.code.info = cmark_chunk_literal(""); S_advance_offset(parser, &input, parser->first_nonspace + matched - parser->offset, diff --git a/src/buffer.c b/src/buffer.c index 26dfb8e..a89c82e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -133,7 +133,7 @@ void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) { void cmark_strbuf_putc(cmark_strbuf *buf, int c) { S_strbuf_grow_by(buf, 1); - buf->ptr[buf->size++] = c; + buf->ptr[buf->size++] = (unsigned char)(c & 0xFF); buf->ptr[buf->size] = '\0'; } diff --git a/src/html.c b/src/html.c index e365c8c..dfe2aec 100644 --- a/src/html.c +++ b/src/html.c @@ -130,12 +130,12 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_HEADER: if (entering) { cr(html); - start_header[2] = '0' + node->as.header.level; + start_header[2] = (char)('0' + node->as.header.level); cmark_strbuf_puts(html, start_header); S_render_sourcepos(node, html, options); cmark_strbuf_putc(html, '>'); } else { - end_header[3] = '0' + node->as.header.level; + end_header[3] = (char)('0' + node->as.header.level); cmark_strbuf_puts(html, end_header); cmark_strbuf_puts(html, ">\n"); } diff --git a/src/utf8.c b/src/utf8.c index a742a75..319539d 100755 --- a/src/utf8.c +++ b/src/utf8.c @@ -191,10 +191,10 @@ void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf) { assert(uc >= 0); if (uc < 0x80) { - dst[0] = uc; + dst[0] = (uint8_t)(uc); len = 1; } else if (uc < 0x800) { - dst[0] = 0xC0 + (uc >> 6); + dst[0] = (uint8_t)(0xC0 + (uc >> 6)); dst[1] = 0x80 + (uc & 0x3F); len = 2; } else if (uc == 0xFFFF) { @@ -204,12 +204,12 @@ void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf) { dst[0] = 0xFE; len = 1; } else if (uc < 0x10000) { - dst[0] = 0xE0 + (uc >> 12); + dst[0] = (uint8_t)(0xE0 + (uc >> 12)); dst[1] = 0x80 + ((uc >> 6) & 0x3F); dst[2] = 0x80 + (uc & 0x3F); len = 3; } else if (uc < 0x110000) { - dst[0] = 0xF0 + (uc >> 18); + dst[0] = (uint8_t)(0xF0 + (uc >> 18)); dst[1] = 0x80 + ((uc >> 12) & 0x3F); dst[2] = 0x80 + ((uc >> 6) & 0x3F); dst[3] = 0x80 + (uc & 0x3F); -- cgit v1.2.3 From 6c51eb5a98521cc2f94dd0139a17f72e025ecfe8 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Mon, 10 Aug 2015 10:07:54 -0700 Subject: Remove need to disable MSVC warning 4244 --- src/CMakeLists.txt | 2 +- src/node.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f04351..30d018f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,7 +155,7 @@ if(MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic") endif() diff --git a/src/node.c b/src/node.c index c5f4553..46d234a 100644 --- a/src/node.c +++ b/src/node.c @@ -717,7 +717,7 @@ int cmark_node_check(cmark_node *node, FILE *out) { } cur = node; - while (true) { + for (;;) { if (cur->first_child) { if (cur->first_child->prev != NULL) { S_print_error(out, cur->first_child, "prev"); -- cgit v1.2.3 From ce0e58469f7c4abf3f51bde6d3298215d6ef99d1 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Mon, 10 Aug 2015 10:09:26 -0700 Subject: Remove need to disable MSVC warning 4267 --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30d018f..f619453 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,7 +155,7 @@ if(MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4706 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS") elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic") endif() -- cgit v1.2.3