diff options
author | Reini Urban <rurban@cpanel.net> | 2016-02-27 11:45:51 +0100 |
---|---|---|
committer | Ingy döt Net <ingy@ingy.net> | 2018-01-08 10:44:25 -0800 |
commit | fc2dd942fc61ae135b7e2bfe5c248b1f15b74547 (patch) | |
tree | 73d890dce146a918cb53c768c7c8117066712476 | |
parent | 2b8b563222293e2cc410cd7fd9cb31f05622d97e (diff) | |
download | libyaml-git-fc2dd942fc61ae135b7e2bfe5c248b1f15b74547.tar.gz |
Fixed most compiler warnings -Wall -Wextra
repro:
CFLAGS="-Wall -Wextra -Wunused-parameter -Wc++-compat" ./configure && make
which we use for perl, and libyaml is now included in cperl.
Tested with gcc-5 and clang-3.7
There are still a tons of format warnings (%d on 64bit) in
example-deconstructor.c which I skipped.
-rw-r--r-- | src/api.c | 51 | ||||
-rw-r--r-- | src/dumper.c | 4 | ||||
-rw-r--r-- | src/emitter.c | 4 | ||||
-rw-r--r-- | src/loader.c | 8 | ||||
-rw-r--r-- | src/parser.c | 22 | ||||
-rw-r--r-- | src/scanner.c | 8 | ||||
-rw-r--r-- | src/yaml_private.h | 39 | ||||
-rw-r--r-- | tests/example-deconstructor.c | 40 | ||||
-rw-r--r-- | tests/example-reformatter.c | 40 | ||||
-rw-r--r-- | tests/run-dumper.c | 6 | ||||
-rw-r--r-- | tests/run-emitter.c | 6 | ||||
-rw-r--r-- | tests/test-reader.c | 28 | ||||
-rw-r--r-- | tests/test-version.c | 6 |
13 files changed, 141 insertions, 121 deletions
@@ -74,7 +74,7 @@ YAML_DECLARE(int) yaml_string_extend(yaml_char_t **start, yaml_char_t **pointer, yaml_char_t **end) { - yaml_char_t *new_start = yaml_realloc(*start, (*end - *start)*2); + yaml_char_t *new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2); if (!new_start) return 0; @@ -94,8 +94,9 @@ yaml_string_extend(yaml_char_t **start, YAML_DECLARE(int) yaml_string_join( yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end, - yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end) + yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end)) { + UNUSED_PARAM(b_end) if (*b_start == *b_pointer) return 1; @@ -177,17 +178,17 @@ yaml_parser_initialize(yaml_parser_t *parser) goto error; if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) goto error; - if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE)) + if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) goto error; - if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->indents, int*)) goto error; - if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) goto error; - if (!STACK_INIT(parser, parser->states, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) goto error; - if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) goto error; - if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) goto error; return 1; @@ -243,7 +244,7 @@ static int yaml_string_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read) { - yaml_parser_t *parser = data; + yaml_parser_t *parser = (yaml_parser_t *)data; if (parser->input.string.current == parser->input.string.end) { *size_read = 0; @@ -269,7 +270,7 @@ static int yaml_file_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read) { - yaml_parser_t *parser = data; + yaml_parser_t *parser = (yaml_parser_t *)data; *size_read = fread(buffer, 1, size, parser->input.file); return !ferror(parser->input.file); @@ -355,13 +356,13 @@ yaml_emitter_initialize(yaml_emitter_t *emitter) goto error; if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) goto error; - if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) goto error; - if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE)) + if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) goto error; - if (!STACK_INIT(emitter, emitter->indents, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->indents, int*)) goto error; - if (!STACK_INIT(emitter, emitter->tag_directives, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) goto error; return 1; @@ -413,7 +414,7 @@ yaml_emitter_delete(yaml_emitter_t *emitter) static int yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) { - yaml_emitter_t *emitter = data; + yaml_emitter_t *emitter = (yaml_emitter_t *)data; if (emitter->output.string.size - *emitter->output.string.size_written < size) { @@ -439,7 +440,7 @@ yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) static int yaml_file_write_handler(void *data, unsigned char *buffer, size_t size) { - yaml_emitter_t *emitter = data; + yaml_emitter_t *emitter = (yaml_emitter_t *)data; return (fwrite(buffer, 1, size, emitter->output.file) == size); } @@ -717,7 +718,7 @@ yaml_document_start_event_initialize(yaml_event_t *event, /* Valid tag directives are expected. */ if (version_directive) { - version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); + version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); if (!version_directive_copy) goto error; version_directive_copy->major = version_directive->major; version_directive_copy->minor = version_directive->minor; @@ -725,7 +726,7 @@ yaml_document_start_event_initialize(yaml_event_t *event, if (tag_directives_start != tag_directives_end) { yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) + if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) goto error; for (tag_directive = tag_directives_start; tag_directive != tag_directives_end; tag_directive ++) { @@ -843,7 +844,7 @@ yaml_scalar_event_initialize(yaml_event_t *event, } if (!yaml_check_utf8(value, length)) goto error; - value_copy = yaml_malloc(length+1); + value_copy = YAML_MALLOC(length+1); if (!value_copy) goto error; memcpy(value_copy, value, length); value_copy[length] = '\0'; @@ -1055,10 +1056,10 @@ yaml_document_initialize(yaml_document_t *document, (tag_directives_start == tag_directives_end)); /* Valid tag directives are expected. */ - if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; if (version_directive) { - version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); + version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); if (!version_directive_copy) goto error; version_directive_copy->major = version_directive->major; version_directive_copy->minor = version_directive->minor; @@ -1066,7 +1067,7 @@ yaml_document_initialize(yaml_document_t *document, if (tag_directives_start != tag_directives_end) { yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) + if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) goto error; for (tag_directive = tag_directives_start; tag_directive != tag_directives_end; tag_directive ++) { @@ -1219,7 +1220,7 @@ yaml_document_add_scalar(yaml_document_t *document, } if (!yaml_check_utf8(value, length)) goto error; - value_copy = yaml_malloc(length+1); + value_copy = YAML_MALLOC(length+1); if (!value_copy) goto error; memcpy(value_copy, value, length); value_copy[length] = '\0'; @@ -1266,7 +1267,7 @@ yaml_document_add_sequence(yaml_document_t *document, tag_copy = yaml_strdup(tag); if (!tag_copy) goto error; - if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, style, mark, mark); @@ -1311,7 +1312,7 @@ yaml_document_add_mapping(yaml_document_t *document, tag_copy = yaml_strdup(tag); if (!tag_copy) goto error; - if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, style, mark, mark); diff --git a/src/dumper.c b/src/dumper.c index 203c6a7..29fb9c0 100644 --- a/src/dumper.c +++ b/src/dumper.c @@ -245,9 +245,9 @@ yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index) #define ANCHOR_TEMPLATE_LENGTH 16 static yaml_char_t * -yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id) +yaml_emitter_generate_anchor(SHIM(yaml_emitter_t *emitter), int anchor_id) { - yaml_char_t *anchor = yaml_malloc(ANCHOR_TEMPLATE_LENGTH); + yaml_char_t *anchor = YAML_MALLOC(ANCHOR_TEMPLATE_LENGTH); if (!anchor) return NULL; diff --git a/src/emitter.c b/src/emitter.c index a5b7ff8..d31e075 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -1002,7 +1002,7 @@ yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, */ static int -yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_event_t *event) +yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event)) { if (!yaml_emitter_process_anchor(emitter)) return 0; @@ -1087,7 +1087,7 @@ yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter, yaml_event_t *event) */ static int -yaml_emitter_check_empty_document(yaml_emitter_t *emitter) +yaml_emitter_check_empty_document(SHIM(yaml_emitter_t *emitter)) { return 0; } diff --git a/src/loader.c b/src/loader.c index 3ba99f0..db8501a 100644 --- a/src/loader.c +++ b/src/loader.c @@ -72,7 +72,7 @@ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document) assert(document); /* Non-NULL document object is expected. */ memset(document, 0, sizeof(yaml_document_t)); - if (!STACK_INIT(parser, document->nodes, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, document->nodes, yaml_node_t*)) goto error; if (!parser->stream_start_produced) { @@ -90,7 +90,7 @@ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document) return 1; } - if (!STACK_INIT(parser, parser->aliases, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->aliases, yaml_alias_data_t*)) goto error; parser->document = document; @@ -339,7 +339,7 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event) if (!tag) goto error; } - if (!STACK_INIT(parser, items, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error; SEQUENCE_NODE_INIT(node, tag, items.start, items.end, first_event->data.sequence_start.style, @@ -402,7 +402,7 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event) if (!tag) goto error; } - if (!STACK_INIT(parser, pairs, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error; MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end, first_event->data.mapping_start.style, diff --git a/src/parser.c b/src/parser.c index dc5430b..621f676 100644 --- a/src/parser.c +++ b/src/parser.c @@ -605,7 +605,7 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { size_t prefix_len = strlen((char *)tag_directive->prefix); size_t suffix_len = strlen((char *)tag_suffix); - tag = yaml_malloc(prefix_len+suffix_len+1); + tag = YAML_MALLOC(prefix_len+suffix_len+1); if (!tag) { parser->error = YAML_MEMORY_ERROR; goto error; @@ -685,7 +685,7 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, return 1; } else if (anchor || tag) { - yaml_char_t *value = yaml_malloc(1); + yaml_char_t *value = YAML_MALLOC(1); if (!value) { parser->error = YAML_MEMORY_ERROR; goto error; @@ -759,9 +759,8 @@ yaml_parser_parse_block_sequence_entry(yaml_parser_t *parser, else if (token->type == YAML_BLOCK_END_TOKEN) { - yaml_mark_t dummy_mark; /* Used to eliminate a compiler warning. */ parser->state = POP(parser, parser->states); - dummy_mark = POP(parser, parser->marks); + (void)POP(parser, parser->marks); SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->end_mark); SKIP_TOKEN(parser); return 1; @@ -869,9 +868,8 @@ yaml_parser_parse_block_mapping_key(yaml_parser_t *parser, else if (token->type == YAML_BLOCK_END_TOKEN) { - yaml_mark_t dummy_mark; /* Used to eliminate a compiler warning. */ parser->state = POP(parser, parser->states); - dummy_mark = POP(parser, parser->marks); + (void)POP(parser, parser->marks); MAPPING_END_EVENT_INIT(*event, token->start_mark, token->end_mark); SKIP_TOKEN(parser); return 1; @@ -952,7 +950,6 @@ yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, yaml_event_t *event, int first) { yaml_token_t *token; - yaml_mark_t dummy_mark; /* Used to eliminate a compiler warning. */ if (first) { token = PEEK_TOKEN(parser); @@ -997,7 +994,7 @@ yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, } parser->state = POP(parser, parser->states); - dummy_mark = POP(parser, parser->marks); + (void)POP(parser, parser->marks); SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->end_mark); SKIP_TOKEN(parser); return 1; @@ -1104,7 +1101,6 @@ yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, yaml_event_t *event, int first) { yaml_token_t *token; - yaml_mark_t dummy_mark; /* Used to eliminate a compiler warning. */ if (first) { token = PEEK_TOKEN(parser); @@ -1158,7 +1154,7 @@ yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, } parser->state = POP(parser, parser->states); - dummy_mark = POP(parser, parser->marks); + (void)POP(parser, parser->marks); MAPPING_END_EVENT_INIT(*event, token->start_mark, token->end_mark); SKIP_TOKEN(parser); return 1; @@ -1212,7 +1208,7 @@ yaml_parser_process_empty_scalar(yaml_parser_t *parser, yaml_event_t *event, { yaml_char_t *value; - value = yaml_malloc(1); + value = YAML_MALLOC(1); if (!value) { parser->error = YAML_MEMORY_ERROR; return 0; @@ -1249,7 +1245,7 @@ yaml_parser_process_directives(yaml_parser_t *parser, } tag_directives = { NULL, NULL, NULL }; yaml_token_t *token; - if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, tag_directives, yaml_tag_directive_t*)) goto error; token = PEEK_TOKEN(parser); @@ -1270,7 +1266,7 @@ yaml_parser_process_directives(yaml_parser_t *parser, "found incompatible YAML document", token->start_mark); goto error; } - version_directive = yaml_malloc(sizeof(yaml_version_directive_t)); + version_directive = YAML_MALLOC_STATIC(yaml_version_directive_t); if (!version_directive) { parser->error = YAML_MEMORY_ERROR; goto error; diff --git a/src/scanner.c b/src/scanner.c index 068dc13..b6f5185 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1186,11 +1186,9 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser) static int yaml_parser_decrease_flow_level(yaml_parser_t *parser) { - yaml_simple_key_t dummy_key; /* Used to eliminate a compiler warning. */ - if (parser->flow_level) { parser->flow_level --; - dummy_key = POP(parser, parser->simple_keys); + (void)POP(parser, parser->simple_keys); } return 1; @@ -2401,7 +2399,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) { /* Set the handle to '' */ - handle = yaml_malloc(1); + handle = YAML_MALLOC(1); if (!handle) goto error; handle[0] = '\0'; @@ -2453,7 +2451,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) /* Set the handle to '!'. */ yaml_free(handle); - handle = yaml_malloc(2); + handle = YAML_MALLOC(2); if (!handle) goto error; handle[0] = '!'; handle[1] = '\0'; diff --git a/src/yaml_private.h b/src/yaml_private.h index 0512328..fe25141 100644 --- a/src/yaml_private.h +++ b/src/yaml_private.h @@ -101,7 +101,7 @@ yaml_parser_fetch_more_tokens(yaml_parser_t *parser); */ #define BUFFER_INIT(context,buffer,size) \ - (((buffer).start = yaml_malloc(size)) ? \ + (((buffer).start = (yaml_char_t *)yaml_malloc(size)) ? \ ((buffer).last = (buffer).pointer = (buffer).start, \ (buffer).end = (buffer).start+(size), \ 1) : \ @@ -141,7 +141,7 @@ yaml_string_join( (value).pointer = (string)) #define STRING_INIT(context,string,size) \ - (((string).start = yaml_malloc(size)) ? \ + (((string).start = YAML_MALLOC(size)) ? \ ((string).pointer = (string).start, \ (string).end = (string).start+(size), \ memset((string).start, 0, (size)), \ @@ -431,10 +431,10 @@ yaml_stack_extend(void **start, void **top, void **end); YAML_DECLARE(int) yaml_queue_extend(void **start, void **head, void **tail, void **end); -#define STACK_INIT(context,stack,size) \ - (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \ +#define STACK_INIT(context,stack,type) \ + (((stack).start = (type)yaml_malloc(INITIAL_STACK_SIZE*sizeof(*(stack).start))) ? \ ((stack).top = (stack).start, \ - (stack).end = (stack).start+(size), \ + (stack).end = (stack).start+INITIAL_STACK_SIZE, \ 1) : \ ((context)->error = YAML_MEMORY_ERROR, \ 0)) @@ -464,8 +464,8 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end); #define POP(context,stack) \ (*(--(stack).top)) -#define QUEUE_INIT(context,queue,size) \ - (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \ +#define QUEUE_INIT(context,queue,size,type) \ + (((queue).start = (type)yaml_malloc((size)*sizeof(*(queue).start))) ? \ ((queue).head = (queue).tail = (queue).start, \ (queue).end = (queue).start+(size), \ 1) : \ @@ -668,3 +668,28 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end); (node).data.mapping.pairs.end = (node_pairs_end), \ (node).data.mapping.pairs.top = (node_pairs_start), \ (node).data.mapping.style = (node_style)) + +/* Strict C compiler warning helpers */ + +#if defined(__clang__) || defined(__GNUC__) +# define HASATTRIBUTE_UNUSED +#endif +#ifdef HASATTRIBUTE_UNUSED +# define __attribute__unused__ __attribute__((__unused__)) +#else +# define __attribute__unused__ +#endif + +/* Shim arguments are arguments that must be included in your function, + * but serve no purpose inside. Silence compiler warnings. */ +#define SHIM(a) /*@unused@*/ a __attribute__unused__ + +/* UNUSED_PARAM() marks a shim argument in the body to silence compiler warnings */ +#ifdef __clang__ +# define UNUSED_PARAM(a) (void)(a); +#else +# define UNUSED_PARAM(a) /*@-noeffect*/if (0) (void)(a)/*@=noeffect*/; +#endif + +#define YAML_MALLOC_STATIC(type) (type*)yaml_malloc(sizeof(type)) +#define YAML_MALLOC(size) (yaml_char_t *)yaml_malloc(size) diff --git a/tests/example-deconstructor.c b/tests/example-deconstructor.c index e904201..e048ee6 100644 --- a/tests/example-deconstructor.c +++ b/tests/example-deconstructor.c @@ -1033,42 +1033,42 @@ parser_error: case YAML_READER_ERROR: if (parser.problem_value != -1) { - fprintf(stderr, "Reader error: %s: #%X at %zu\n", parser.problem, - parser.problem_value, parser.problem_offset); + fprintf(stderr, "Reader error: %s: #%X at %ld\n", parser.problem, + parser.problem_value, (long)parser.problem_offset); } else { - fprintf(stderr, "Reader error: %s at %zu\n", parser.problem, - parser.problem_offset); + fprintf(stderr, "Reader error: %s at %ld\n", parser.problem, + (long)parser.problem_offset); } break; case YAML_SCANNER_ERROR: if (parser.context) { - fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n" - "%s at line %lu, column %lu\n", parser.context, - parser.context_mark.line+1, parser.context_mark.column+1, - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Scanner error: %s at line %d, column %d\n" + "%s at line %d, column %d\n", parser.context, + (int)parser.context_mark.line+1, (int)parser.context_mark.column+1, + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } else { - fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n", - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Scanner error: %s at line %d, column %d\n", + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser.context) { - fprintf(stderr, "Parser error: %s at line %lu, column %lu\n" - "%s at line %lu, column %lu\n", parser.context, - parser.context_mark.line+1, parser.context_mark.column+1, - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Parser error: %s at line %d, column %d\n" + "%s at line %d, column %d\n", parser.context, + (int)parser.context_mark.line+1, (int)parser.context_mark.column+1, + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } else { - fprintf(stderr, "Parser error: %s at line %lu, column %lu\n", - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Parser error: %s at line %d, column %d\n", + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } break; diff --git a/tests/example-reformatter.c b/tests/example-reformatter.c index 306c742..08f860c 100644 --- a/tests/example-reformatter.c +++ b/tests/example-reformatter.c @@ -120,42 +120,42 @@ parser_error: case YAML_READER_ERROR: if (parser.problem_value != -1) { - fprintf(stderr, "Reader error: %s: #%X at %zd\n", parser.problem, - parser.problem_value, parser.problem_offset); + fprintf(stderr, "Reader error: %s: #%X at %ld\n", parser.problem, + parser.problem_value, (long)parser.problem_offset); } else { - fprintf(stderr, "Reader error: %s at %zd\n", parser.problem, - parser.problem_offset); + fprintf(stderr, "Reader error: %s at %ld\n", parser.problem, + (long)parser.problem_offset); } break; case YAML_SCANNER_ERROR: if (parser.context) { - fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n" - "%s at line %lu, column %lu\n", parser.context, - parser.context_mark.line+1, parser.context_mark.column+1, - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Scanner error: %s at line %d, column %d\n" + "%s at line %d, column %d\n", parser.context, + (int)parser.context_mark.line+1, (int)parser.context_mark.column+1, + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } else { - fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n", - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Scanner error: %s at line %d, column %d\n", + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser.context) { - fprintf(stderr, "Parser error: %s at line %lu, column %lu\n" - "%s at line %lu, column %lu\n", parser.context, - parser.context_mark.line+1, parser.context_mark.column+1, - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Parser error: %s at line %d, column %d\n" + "%s at line %d, column %d\n", parser.context, + (int)parser.context_mark.line+1, (int)parser.context_mark.column+1, + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } else { - fprintf(stderr, "Parser error: %s at line %lu, column %lu\n", - parser.problem, parser.problem_mark.line+1, - parser.problem_mark.column+1); + fprintf(stderr, "Parser error: %s at line %d, column %d\n", + parser.problem, (int)parser.problem_mark.line+1, + (int)parser.problem_mark.column+1); } break; diff --git a/tests/run-dumper.c b/tests/run-dumper.c index 6236ee1..302b9b9 100644 --- a/tests/run-dumper.c +++ b/tests/run-dumper.c @@ -180,8 +180,8 @@ int print_output(char *name, unsigned char *buffer, size_t size, int count) if (feof(file)) break; } fclose(file); - printf("#### (length: %zd)\n", total_size); - printf("OUTPUT:\n%s#### (length: %zd)\n", buffer, size); + printf("#### (length: %ld)\n", (long)total_size); + printf("OUTPUT:\n%s#### (length: %ld)\n", buffer, (long)size); return 0; } @@ -304,7 +304,7 @@ main(int argc, char *argv[]) yaml_document_delete(documents+k); } - printf("PASSED (length: %zd)\n", written); + printf("PASSED (length: %ld)\n", (long)written); print_output(argv[number], buffer, written, -1); } diff --git a/tests/run-emitter.c b/tests/run-emitter.c index fee2922..4996a85 100644 --- a/tests/run-emitter.c +++ b/tests/run-emitter.c @@ -205,8 +205,8 @@ int print_output(char *name, unsigned char *buffer, size_t size, int count) if (feof(file)) break; } fclose(file); - printf("#### (length: %zd)\n", total_size); - printf("OUTPUT:\n%s#### (length: %zd)\n", buffer, size); + printf("#### (length: %ld)\n", (long)total_size); + printf("OUTPUT:\n%s#### (length: %ld)\n", buffer, (long)size); return 0; } @@ -319,7 +319,7 @@ main(int argc, char *argv[]) yaml_event_delete(events+k); } - printf("PASSED (length: %zd)\n", written); + printf("PASSED (length: %ld)\n", (long)written); print_output(argv[number], buffer, written, -1); } diff --git a/tests/test-reader.c b/tests/test-reader.c index 2ecb292..40f8199 100644 --- a/tests/test-reader.c +++ b/tests/test-reader.c @@ -144,12 +144,12 @@ int check_utf8_sequences(void) } else if (parser.error == YAML_READER_ERROR) { if (parser.problem_value != -1) { - printf("(reader error: %s: #%X at %zu)\n", - parser.problem, parser.problem_value, parser.problem_offset); + printf("(reader error: %s: #%X at %ld)\n", + parser.problem, parser.problem_value, (long)parser.problem_offset); } else { - printf("(reader error: %s at %zu)\n", - parser.problem, parser.problem_offset); + printf("(reader error: %s at %ld)\n", + parser.problem, (long)parser.problem_offset); } } if (*end == '!') break; @@ -180,12 +180,12 @@ int check_boms(void) yaml_parser_set_input_string(&parser, (unsigned char *)start, end-start); result = yaml_parser_update_buffer(&parser, end-start); if (!result) { - printf("- (reader error: %s at %zu)\n", parser.problem, parser.problem_offset); + printf("- (reader error: %s at %ld)\n", parser.problem, (long)parser.problem_offset); failed++; } else { if (parser.unread != check) { - printf("- (length=%zu while expected length=%d)\n", parser.unread, check); + printf("- (length=%ld while expected length=%d)\n", (long)parser.unread, check); failed++; } else if (memcmp(parser.buffer.start, bom_original, check) != 0) { @@ -211,7 +211,7 @@ int check_long_utf8(void) int j; int failed = 0; unsigned char ch0, ch1; - unsigned char *buffer = malloc(3+LONG*2); + unsigned char *buffer = (unsigned char *)malloc(3+LONG*2); assert(buffer); printf("checking a long utf8 sequence...\n"); buffer[k++] = '\xef'; @@ -232,7 +232,7 @@ int check_long_utf8(void) for (k = 0; k < LONG; k++) { if (!parser.unread) { if (!yaml_parser_update_buffer(&parser, 1)) { - printf("\treader error: %s at %zu\n", parser.problem, parser.problem_offset); + printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset); failed = 1; break; } @@ -262,11 +262,11 @@ int check_long_utf8(void) } if (!failed) { if (!yaml_parser_update_buffer(&parser, 1)) { - printf("\treader error: %s at %zu\n", parser.problem, parser.problem_offset); + printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset); failed = 1; } else if (parser.buffer.pointer[0] != '\0') { - printf("\texpected NUL, found %X (eof=%d, unread=%zu)\n", (int)parser.buffer.pointer[0], parser.eof, parser.unread); + printf("\texpected NUL, found %X (eof=%d, unread=%ld)\n", (int)parser.buffer.pointer[0], parser.eof, (long)parser.unread); failed = 1; } } @@ -283,7 +283,7 @@ int check_long_utf16(void) int j; int failed = 0; unsigned char ch0, ch1; - unsigned char *buffer = malloc(2+LONG*2); + unsigned char *buffer = (unsigned char *)malloc(2+LONG*2); assert(buffer); printf("checking a long utf16 sequence...\n"); buffer[k++] = '\xff'; @@ -303,7 +303,7 @@ int check_long_utf16(void) for (k = 0; k < LONG; k++) { if (!parser.unread) { if (!yaml_parser_update_buffer(&parser, 1)) { - printf("\treader error: %s at %zu\n", parser.problem, parser.problem_offset); + printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset); failed = 1; break; } @@ -333,11 +333,11 @@ int check_long_utf16(void) } if (!failed) { if (!yaml_parser_update_buffer(&parser, 1)) { - printf("\treader error: %s at %zu\n", parser.problem, parser.problem_offset); + printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset); failed = 1; } else if (parser.buffer.pointer[0] != '\0') { - printf("\texpected NUL, found %X (eof=%d, unread=%zu)\n", (int)parser.buffer.pointer[0], parser.eof, parser.unread); + printf("\texpected NUL, found %X (eof=%d, unread=%ld)\n", (int)parser.buffer.pointer[0], parser.eof, (long)parser.unread); failed = 1; } } diff --git a/tests/test-version.c b/tests/test-version.c index 69ae5bb..0c59837 100644 --- a/tests/test-version.c +++ b/tests/test-version.c @@ -21,9 +21,9 @@ main(void) assert(strcmp(buf, yaml_get_version_string()) == 0); /* Print structure sizes. */ - printf("sizeof(token) = %lu\n", sizeof(yaml_token_t)); - printf("sizeof(event) = %lu\n", sizeof(yaml_event_t)); - printf("sizeof(parser) = %lu\n", sizeof(yaml_parser_t)); + printf("sizeof(token) = %ld\n", (long)sizeof(yaml_token_t)); + printf("sizeof(event) = %ld\n", (long)sizeof(yaml_event_t)); + printf("sizeof(parser) = %ld\n", (long)sizeof(yaml_parser_t)); return 0; } |