Skip to content

Commit

Permalink
Get a clean build on MSVC (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Izumi authored and Yuki Izumi committed Jun 30, 2017
1 parent 6a1fd59 commit f2d61da
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 61 deletions.
2 changes: 1 addition & 1 deletion api_test/main.c
Expand Up @@ -479,7 +479,7 @@ static void test_content(test_batch_runner *runner, cmark_node_type type,
int expected = 0;
if (allowed_content)
for (unsigned int *p = allowed_content; *p; ++p)
expected |= *p == child_type;
expected |= *p == (unsigned int)child_type;

INT_EQ(runner, got, expected, "add %d as child of %d", child_type, type);

Expand Down
2 changes: 1 addition & 1 deletion extensions/CMakeLists.txt
Expand Up @@ -68,7 +68,7 @@ if(MSVC)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /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 -Wno-unused-parameter -std=c99 -pedantic")
endif()
Expand Down
33 changes: 18 additions & 15 deletions extensions/autolink.c
Expand Up @@ -75,7 +75,7 @@ static size_t autolink_delim(uint8_t *data, size_t link_end) {
} else if (copen != 0) {
size_t closing = 0;
size_t opening = 0;
size_t i = 0;
i = 0;

/* Try to close the final punctuation sign in this same line;
* if we managed to close it outside of the URL, that means that it's
Expand Down Expand Up @@ -176,30 +176,32 @@ static cmark_node *www_match(cmark_parser *parser, cmark_node *parent,
if (link_end == 0)
return NULL;

cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));

cmark_node *node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);

cmark_strbuf buf;
cmark_strbuf_init(parser->mem, &buf, 10);
cmark_strbuf_puts(&buf, "http://");
cmark_strbuf_put(&buf, data, link_end);
cmark_strbuf_put(&buf, data, (bufsize_t)link_end);
node->as.link.url = cmark_chunk_buf_detach(&buf);

cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
text->as.literal = cmark_chunk_dup(chunk, max_rewind, link_end);
text->as.literal =
cmark_chunk_dup(chunk, (bufsize_t)max_rewind, (bufsize_t)link_end);
cmark_node_append_child(node, text);

return node;
}

static cmark_node *email_match(cmark_parser *parser, cmark_node *parent,
cmark_inline_parser *inline_parser) {
size_t link_end, rewind;
size_t link_end;
int rewind;
int nb = 0, np = 0, ns = 0;

cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser);
size_t max_rewind = cmark_inline_parser_get_offset(inline_parser);
int max_rewind = cmark_inline_parser_get_offset(inline_parser);
uint8_t *data = chunk->data + max_rewind;
size_t size = chunk->len - max_rewind;

Expand Down Expand Up @@ -244,31 +246,32 @@ static cmark_node *email_match(cmark_parser *parser, cmark_node *parent,
if (link_end == 0)
return NULL;

cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));
cmark_node_unput(parent, rewind);

cmark_node *node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);

cmark_strbuf buf;
cmark_strbuf_init(parser->mem, &buf, 10);
cmark_strbuf_puts(&buf, "mailto:");
cmark_strbuf_put(&buf, data - rewind, link_end + rewind);
cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
node->as.link.url = cmark_chunk_buf_detach(&buf);

cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
text->as.literal =
cmark_chunk_dup(chunk, max_rewind - rewind, link_end + rewind);
text->as.literal = cmark_chunk_dup(chunk, max_rewind - rewind,
(bufsize_t)(link_end + rewind));
cmark_node_append_child(node, text);

return node;
}

static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
cmark_inline_parser *inline_parser) {
size_t link_end, rewind = 0, domain_len;
size_t link_end, domain_len;
int rewind = 0;

cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser);
size_t max_rewind = cmark_inline_parser_get_offset(inline_parser);
int max_rewind = cmark_inline_parser_get_offset(inline_parser);
uint8_t *data = chunk->data + max_rewind;
size_t size = chunk->len - max_rewind;

Expand Down Expand Up @@ -297,13 +300,13 @@ static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
if (link_end == 0)
return NULL;

cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));
cmark_node_unput(parent, rewind);

cmark_node *node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);

cmark_chunk url =
cmark_chunk_dup(chunk, max_rewind - rewind, link_end + rewind);
cmark_chunk url = cmark_chunk_dup(chunk, max_rewind - rewind,
(bufsize_t)(link_end + rewind));
node->as.link.url = url;

cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
Expand Down
22 changes: 11 additions & 11 deletions extensions/table.c
Expand Up @@ -30,18 +30,18 @@ typedef enum {
typedef struct { bool is_header; } node_table_row;

static void free_node_table(cmark_mem *mem, void *ptr) {
node_table *t = ptr;
node_table *t = (node_table *)ptr;
mem->free(t->alignments);
mem->free(t);
}

static void free_node_table_row(cmark_mem *mem, void *ptr) { mem->free(ptr); }

static uint16_t get_n_table_columns(cmark_node *node) {
static int get_n_table_columns(cmark_node *node) {
if (!node || node->type != CMARK_NODE_TABLE)
return -1;

return ((node_table *)node->user_data)->n_columns;
return (int)((node_table *)node->user_data)->n_columns;
}

static int set_n_table_columns(cmark_node *node, uint16_t n_columns) {
Expand Down Expand Up @@ -71,7 +71,7 @@ static int is_table_header(cmark_node *node, int is_table_header) {
if (!node || node->type != CMARK_NODE_TABLE_ROW)
return 0;

((node_table_row *)node->user_data)->is_header = is_table_header;
((node_table_row *)node->user_data)->is_header = (is_table_header != 0);
return 1;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ static cmark_node *consume_until_pipe_or_eol(cmark_syntax_extension *self,
(*n)->as.literal.len - *offset);
cmark_node_own(child);
} else {
int len = pipe - cstr - *offset;
int len = (int)(pipe - cstr - *offset);
child->as.literal = cmark_chunk_dup(&(*n)->as.literal, *offset, len);
cmark_node_own(child);
*offset += len + 1;
Expand Down Expand Up @@ -245,7 +245,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
parent_string = cmark_node_get_string_content(parent_container);

header_row = row_from_string(self, parser, (unsigned char *)parent_string,
strlen(parent_string));
(int)strlen(parent_string));

if (!header_row) {
goto done;
Expand Down Expand Up @@ -274,10 +274,10 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
set_n_table_columns(parent_container, header_row->n_columns);

uint8_t *alignments =
parser->mem->calloc(header_row->n_columns, sizeof(uint8_t));
(uint8_t *)parser->mem->calloc(header_row->n_columns, sizeof(uint8_t));
cmark_llist *it = marker_row->cells;
for (i = 0; it; it = it->next, ++i) {
cmark_node *node = it->data;
cmark_node *node = (cmark_node *)it->data;
assert(node->type == CMARK_NODE_TABLE_CELL);

cmark_strbuf strbuf;
Expand Down Expand Up @@ -315,7 +315,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
cmark_llist *tmp, *next;

for (tmp = header_row->cells; tmp; tmp = next) {
cmark_node *header_cell = tmp->data;
cmark_node *header_cell = (cmark_node *)tmp->data;
cmark_node_append_child(table_header, header_cell);
next = header_row->cells = tmp->next;
parser->mem->free(tmp);
Expand All @@ -324,7 +324,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,

cmark_parser_advance_offset(
parser, (char *)input,
strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false);
(int)strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false);
done:
free_table_row(parser->mem, header_row);
free_table_row(parser->mem, marker_row);
Expand Down Expand Up @@ -362,7 +362,7 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
int table_columns = get_n_table_columns(parent_container);

for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = next, ++i) {
cmark_node *cell = tmp->data;
cmark_node *cell = (cmark_node *)tmp->data;
assert(cell->type == CMARK_NODE_TABLE_CELL);
cmark_node_append_child(table_row_block, cell);
row->cells = next = tmp->next;
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -199,7 +199,7 @@ if(MSVC)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /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 -Wno-unused-parameter -std=c99 -pedantic")
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/arena.c
Expand Up @@ -10,7 +10,7 @@ static struct arena_chunk {
} *A = NULL;

static struct arena_chunk *alloc_arena_chunk(size_t sz, struct arena_chunk *prev) {
struct arena_chunk *c = calloc(1, sizeof(*c));
struct arena_chunk *c = (struct arena_chunk *)calloc(1, sizeof(*c));
if (!c)
abort();
c->sz = sz;
Expand Down
10 changes: 5 additions & 5 deletions src/blocks.c
Expand Up @@ -181,7 +181,7 @@ static CMARK_INLINE bool accepts_lines(cmark_node_type block_type) {

static CMARK_INLINE bool contains_inlines(cmark_node *node) {
if (node->extension && node->extension->contains_inlines_func) {
return node->extension->contains_inlines_func(node->extension, node);
return node->extension->contains_inlines_func(node->extension, node) != 0;
}

return (node->type == CMARK_NODE_PARAGRAPH ||
Expand Down Expand Up @@ -392,7 +392,7 @@ void cmark_manage_extensions_special_characters(cmark_parser *parser, bool add)
cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp_ext->data;
cmark_llist *tmp_char;
for (tmp_char = ext->special_inline_chars; tmp_char; tmp_char=tmp_char->next) {
unsigned char c = (unsigned char) (unsigned long) tmp_char->data;
unsigned char c = (unsigned char)(size_t)tmp_char->data;
if (add)
cmark_inlines_add_special_character(c);
else
Expand Down Expand Up @@ -607,7 +607,7 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
process = true;
}

chunk_len = (eol - buffer);
chunk_len = (bufsize_t)(eol - buffer);
if (process) {
if (parser->linebuf.size > 0) {
cmark_strbuf_put(&parser->linebuf, buffer, chunk_len);
Expand Down Expand Up @@ -987,7 +987,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,
parser->first_nonspace + 1);
(*container)->as.code.fenced = true;
(*container)->as.code.fence_char = peek_at(input, parser->first_nonspace);
(*container)->as.code.fence_length = (matched > 255) ? 255 : matched;
(*container)->as.code.fence_length = (matched > 255) ? 255 : (uint8_t)matched;
(*container)->as.code.fence_offset =
(int8_t)(parser->first_nonspace - parser->offset);
(*container)->as.code.info = cmark_chunk_literal("");
Expand Down Expand Up @@ -1383,5 +1383,5 @@ void cmark_parser_advance_offset(cmark_parser *parser,
int columns) {
cmark_chunk input_chunk = cmark_chunk_literal(input);

S_advance_offset(parser, &input_chunk, count, columns);
S_advance_offset(parser, &input_chunk, count, columns != 0);
}
4 changes: 2 additions & 2 deletions src/buffer.c
Expand Up @@ -96,7 +96,7 @@ void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,

void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) {
cmark_strbuf_set(buf, (const unsigned char *)string,
string ? strlen(string) : 0);
string ? (bufsize_t)strlen(string) : 0);
}

void cmark_strbuf_putc(cmark_strbuf *buf, int c) {
Expand All @@ -117,7 +117,7 @@ void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
}

void cmark_strbuf_puts(cmark_strbuf *buf, const char *string) {
cmark_strbuf_put(buf, (const unsigned char *)string, strlen(string));
cmark_strbuf_put(buf, (const unsigned char *)string, (bufsize_t)strlen(string));
}

void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
Expand Down
6 changes: 5 additions & 1 deletion src/cmark.c
Expand Up @@ -32,7 +32,11 @@ static void *xrealloc(void *ptr, size_t size) {
return new_ptr;
}

cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, free};
static void xfree(void *ptr) {
free(ptr);
}

cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree};

cmark_mem *cmark_get_default_mem_allocator() {
return &CMARK_DEFAULT_MEM_ALLOCATOR;
Expand Down
6 changes: 3 additions & 3 deletions src/commonmark.c
Expand Up @@ -43,13 +43,13 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape,
(renderer->begin_content && (c == '.' || c == ')') && follows_digit &&
(nextc == 0 || cmark_isspace(nextc))))) ||
(escape == URL &&
(c == '`' || c == '<' || c == '>' || cmark_isspace(c) || c == '\\' ||
(c == '`' || c == '<' || c == '>' || cmark_isspace((char)c) || c == '\\' ||
c == ')' || c == '(')) ||
(escape == TITLE &&
(c == '`' || c == '<' || c == '>' || c == '"' || c == '\\')));

if (needs_escaping) {
if (cmark_isspace(c)) {
if (cmark_isspace((char)c)) {
// use percent encoding for spaces
snprintf(encoded, ENCODED_SIZE, "%%%2x", c);
cmark_strbuf_puts(renderer->buffer, encoded);
Expand Down Expand Up @@ -239,7 +239,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number,
list_delim == CMARK_PAREN_DELIM ? ")" : ".",
list_number < 10 ? " " : " ");
marker_width = strlen(listmarker);
marker_width = (bufsize_t)strlen(listmarker);
}
if (entering) {
if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
Expand Down
4 changes: 2 additions & 2 deletions src/html.c
Expand Up @@ -30,7 +30,7 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
break;

if (match != data) {
cmark_strbuf_put(html, data, match - data);
cmark_strbuf_put(html, data, (bufsize_t)(match - data));
len -= (match - data);
data = match;
}
Expand All @@ -55,7 +55,7 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
}

if (len)
cmark_strbuf_put(html, data, len);
cmark_strbuf_put(html, data, (bufsize_t)len);
}

static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
Expand Down

0 comments on commit f2d61da

Please sign in to comment.