Skip to content

Commit c36f848

Browse files
Yuki IzumiYuki Izumi
authored andcommitted
Get a clean build on MSVC (#5)
1 parent 3e5f8a4 commit c36f848

File tree

14 files changed

+68
-61
lines changed

14 files changed

+68
-61
lines changed

api_test/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static void test_content(test_batch_runner *runner, cmark_node_type type,
479479
int expected = 0;
480480
if (allowed_content)
481481
for (unsigned int *p = allowed_content; *p; ++p)
482-
expected |= *p == child_type;
482+
expected |= *p == (unsigned int)child_type;
483483

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

extensions/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if(MSVC)
6868
else()
6969
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
7070
endif()
71-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
71+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /D_CRT_SECURE_NO_WARNINGS")
7272
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
7373
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99 -pedantic")
7474
endif()

extensions/autolink.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static size_t autolink_delim(uint8_t *data, size_t link_end) {
7575
} else if (copen != 0) {
7676
size_t closing = 0;
7777
size_t opening = 0;
78-
size_t i = 0;
78+
i = 0;
7979

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

179-
cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
179+
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));
180180

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

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

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

193194
return node;
194195
}
195196

196197
static cmark_node *email_match(cmark_parser *parser, cmark_node *parent,
197198
cmark_inline_parser *inline_parser) {
198-
size_t link_end, rewind;
199+
size_t link_end;
200+
int rewind;
199201
int nb = 0, np = 0, ns = 0;
200202

201203
cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser);
202-
size_t max_rewind = cmark_inline_parser_get_offset(inline_parser);
204+
int max_rewind = cmark_inline_parser_get_offset(inline_parser);
203205
uint8_t *data = chunk->data + max_rewind;
204206
size_t size = chunk->len - max_rewind;
205207

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

247-
cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
249+
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));
248250
cmark_node_unput(parent, rewind);
249251

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

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

258260
cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
259-
text->as.literal =
260-
cmark_chunk_dup(chunk, max_rewind - rewind, link_end + rewind);
261+
text->as.literal = cmark_chunk_dup(chunk, max_rewind - rewind,
262+
(bufsize_t)(link_end + rewind));
261263
cmark_node_append_child(node, text);
262264

263265
return node;
264266
}
265267

266268
static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
267269
cmark_inline_parser *inline_parser) {
268-
size_t link_end, rewind = 0, domain_len;
270+
size_t link_end, domain_len;
271+
int rewind = 0;
269272

270273
cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser);
271-
size_t max_rewind = cmark_inline_parser_get_offset(inline_parser);
274+
int max_rewind = cmark_inline_parser_get_offset(inline_parser);
272275
uint8_t *data = chunk->data + max_rewind;
273276
size_t size = chunk->len - max_rewind;
274277

@@ -297,13 +300,13 @@ static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
297300
if (link_end == 0)
298301
return NULL;
299302

300-
cmark_inline_parser_set_offset(inline_parser, max_rewind + link_end);
303+
cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end));
301304
cmark_node_unput(parent, rewind);
302305

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

305-
cmark_chunk url =
306-
cmark_chunk_dup(chunk, max_rewind - rewind, link_end + rewind);
308+
cmark_chunk url = cmark_chunk_dup(chunk, max_rewind - rewind,
309+
(bufsize_t)(link_end + rewind));
307310
node->as.link.url = url;
308311

309312
cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);

extensions/table.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ typedef enum {
3030
typedef struct { bool is_header; } node_table_row;
3131

3232
static void free_node_table(cmark_mem *mem, void *ptr) {
33-
node_table *t = ptr;
33+
node_table *t = (node_table *)ptr;
3434
mem->free(t->alignments);
3535
mem->free(t);
3636
}
3737

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

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

44-
return ((node_table *)node->user_data)->n_columns;
44+
return (int)((node_table *)node->user_data)->n_columns;
4545
}
4646

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

74-
((node_table_row *)node->user_data)->is_header = is_table_header;
74+
((node_table_row *)node->user_data)->is_header = (is_table_header != 0);
7575
return 1;
7676
}
7777

@@ -159,7 +159,7 @@ static cmark_node *consume_until_pipe_or_eol(cmark_syntax_extension *self,
159159
(*n)->as.literal.len - *offset);
160160
cmark_node_own(child);
161161
} else {
162-
int len = pipe - cstr - *offset;
162+
int len = (int)(pipe - cstr - *offset);
163163
child->as.literal = cmark_chunk_dup(&(*n)->as.literal, *offset, len);
164164
cmark_node_own(child);
165165
*offset += len + 1;
@@ -245,7 +245,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
245245
parent_string = cmark_node_get_string_content(parent_container);
246246

247247
header_row = row_from_string(self, parser, (unsigned char *)parent_string,
248-
strlen(parent_string));
248+
(int)strlen(parent_string));
249249

250250
if (!header_row) {
251251
goto done;
@@ -274,10 +274,10 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
274274
set_n_table_columns(parent_container, header_row->n_columns);
275275

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

283283
cmark_strbuf strbuf;
@@ -315,7 +315,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
315315
cmark_llist *tmp, *next;
316316

317317
for (tmp = header_row->cells; tmp; tmp = next) {
318-
cmark_node *header_cell = tmp->data;
318+
cmark_node *header_cell = (cmark_node *)tmp->data;
319319
cmark_node_append_child(table_header, header_cell);
320320
next = header_row->cells = tmp->next;
321321
parser->mem->free(tmp);
@@ -324,7 +324,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
324324

325325
cmark_parser_advance_offset(
326326
parser, (char *)input,
327-
strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false);
327+
(int)strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false);
328328
done:
329329
free_table_row(parser->mem, header_row);
330330
free_table_row(parser->mem, marker_row);
@@ -362,7 +362,7 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
362362
int table_columns = get_n_table_columns(parent_container);
363363

364364
for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = next, ++i) {
365-
cmark_node *cell = tmp->data;
365+
cmark_node *cell = (cmark_node *)tmp->data;
366366
assert(cell->type == CMARK_NODE_TABLE_CELL);
367367
cmark_node_append_child(table_row_block, cell);
368368
row->cells = next = tmp->next;

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ if(MSVC)
199199
else()
200200
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
201201
endif()
202-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
202+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /D_CRT_SECURE_NO_WARNINGS")
203203
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
204204
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99 -pedantic")
205205
endif()

src/arena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static struct arena_chunk {
1010
} *A = NULL;
1111

1212
static struct arena_chunk *alloc_arena_chunk(size_t sz, struct arena_chunk *prev) {
13-
struct arena_chunk *c = calloc(1, sizeof(*c));
13+
struct arena_chunk *c = (struct arena_chunk *)calloc(1, sizeof(*c));
1414
if (!c)
1515
abort();
1616
c->sz = sz;

src/blocks.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static CMARK_INLINE bool accepts_lines(cmark_node_type block_type) {
181181

182182
static CMARK_INLINE bool contains_inlines(cmark_node *node) {
183183
if (node->extension && node->extension->contains_inlines_func) {
184-
return node->extension->contains_inlines_func(node->extension, node);
184+
return node->extension->contains_inlines_func(node->extension, node) != 0;
185185
}
186186

187187
return (node->type == CMARK_NODE_PARAGRAPH ||
@@ -392,7 +392,7 @@ void cmark_manage_extensions_special_characters(cmark_parser *parser, bool add)
392392
cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp_ext->data;
393393
cmark_llist *tmp_char;
394394
for (tmp_char = ext->special_inline_chars; tmp_char; tmp_char=tmp_char->next) {
395-
unsigned char c = (unsigned char) (unsigned long) tmp_char->data;
395+
unsigned char c = (unsigned char)(size_t)tmp_char->data;
396396
if (add)
397397
cmark_inlines_add_special_character(c);
398398
else
@@ -607,7 +607,7 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
607607
process = true;
608608
}
609609

610-
chunk_len = (eol - buffer);
610+
chunk_len = (bufsize_t)(eol - buffer);
611611
if (process) {
612612
if (parser->linebuf.size > 0) {
613613
cmark_strbuf_put(&parser->linebuf, buffer, chunk_len);
@@ -987,7 +987,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,
987987
parser->first_nonspace + 1);
988988
(*container)->as.code.fenced = true;
989989
(*container)->as.code.fence_char = peek_at(input, parser->first_nonspace);
990-
(*container)->as.code.fence_length = (matched > 255) ? 255 : matched;
990+
(*container)->as.code.fence_length = (matched > 255) ? 255 : (uint8_t)matched;
991991
(*container)->as.code.fence_offset =
992992
(int8_t)(parser->first_nonspace - parser->offset);
993993
(*container)->as.code.info = cmark_chunk_literal("");
@@ -1383,5 +1383,5 @@ void cmark_parser_advance_offset(cmark_parser *parser,
13831383
int columns) {
13841384
cmark_chunk input_chunk = cmark_chunk_literal(input);
13851385

1386-
S_advance_offset(parser, &input_chunk, count, columns);
1386+
S_advance_offset(parser, &input_chunk, count, columns != 0);
13871387
}

src/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
9696

9797
void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) {
9898
cmark_strbuf_set(buf, (const unsigned char *)string,
99-
string ? strlen(string) : 0);
99+
string ? (bufsize_t)strlen(string) : 0);
100100
}
101101

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

119119
void cmark_strbuf_puts(cmark_strbuf *buf, const char *string) {
120-
cmark_strbuf_put(buf, (const unsigned char *)string, strlen(string));
120+
cmark_strbuf_put(buf, (const unsigned char *)string, (bufsize_t)strlen(string));
121121
}
122122

123123
void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,

src/cmark.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ static void *xrealloc(void *ptr, size_t size) {
3232
return new_ptr;
3333
}
3434

35-
cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, free};
35+
static void xfree(void *ptr) {
36+
free(ptr);
37+
}
38+
39+
cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree};
3640

3741
cmark_mem *cmark_get_default_mem_allocator() {
3842
return &CMARK_DEFAULT_MEM_ALLOCATOR;

src/commonmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape,
4343
(renderer->begin_content && (c == '.' || c == ')') && follows_digit &&
4444
(nextc == 0 || cmark_isspace(nextc))))) ||
4545
(escape == URL &&
46-
(c == '`' || c == '<' || c == '>' || cmark_isspace(c) || c == '\\' ||
46+
(c == '`' || c == '<' || c == '>' || cmark_isspace((char)c) || c == '\\' ||
4747
c == ')' || c == '(')) ||
4848
(escape == TITLE &&
4949
(c == '`' || c == '<' || c == '>' || c == '"' || c == '\\')));
5050

5151
if (needs_escaping) {
52-
if (cmark_isspace(c)) {
52+
if (cmark_isspace((char)c)) {
5353
// use percent encoding for spaces
5454
snprintf(encoded, ENCODED_SIZE, "%%%2x", c);
5555
cmark_strbuf_puts(renderer->buffer, encoded);
@@ -239,7 +239,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
239239
snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number,
240240
list_delim == CMARK_PAREN_DELIM ? ")" : ".",
241241
list_number < 10 ? " " : " ");
242-
marker_width = strlen(listmarker);
242+
marker_width = (bufsize_t)strlen(listmarker);
243243
}
244244
if (entering) {
245245
if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {

src/html.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
3030
break;
3131

3232
if (match != data) {
33-
cmark_strbuf_put(html, data, match - data);
33+
cmark_strbuf_put(html, data, (bufsize_t)(match - data));
3434
len -= (match - data);
3535
data = match;
3636
}
@@ -55,7 +55,7 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
5555
}
5656

5757
if (len)
58-
cmark_strbuf_put(html, data, len);
58+
cmark_strbuf_put(html, data, (bufsize_t)len);
5959
}
6060

6161
static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,

0 commit comments

Comments
 (0)