From 2f62cdac3197ceeaf6c283b71af6461a4bb766b5 Mon Sep 17 00:00:00 2001 From: "Randall S. Becker" Date: Tue, 22 Mar 2022 15:01:57 -0400 Subject: [PATCH] Resolve type conversion warnings for c99 and above compilers. Signed-off-by: Randall S. Becker --- src/api.c | 4 ++-- src/emitter.c | 4 ++-- src/loader.c | 2 +- src/reader.c | 28 ++++++++++++------------- src/scanner.c | 34 +++++++++++++++---------------- src/writer.c | 12 +++++------ tests/example-deconstructor-alt.c | 2 +- tests/example-deconstructor.c | 2 +- tests/run-dumper.c | 2 +- tests/run-emitter-test-suite.c | 6 +++--- tests/run-emitter.c | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/api.c b/src/api.c index 16f88bd7..2034e8c5 100644 --- a/src/api.c +++ b/src/api.c @@ -845,7 +845,7 @@ yaml_scalar_event_initialize(yaml_event_t *event, } if (length < 0) { - length = strlen((char *)value); + length = (int) strlen((char *)value); } if (!yaml_check_utf8(value, length)) goto error; @@ -1216,7 +1216,7 @@ yaml_document_add_scalar(yaml_document_t *document, if (!tag_copy) goto error; if (length < 0) { - length = strlen((char *)value); + length = (int) strlen((char *)value); } if (!yaml_check_utf8(value, length)) goto error; diff --git a/src/emitter.c b/src/emitter.c index 609b28a4..632afbcf 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -2162,8 +2162,8 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, if (!PUT(emitter, 'U')) return 0; width = 8; } - for (k = (width-1)*4; k >= 0; k -= 4) { - int digit = (value >> k) & 0x0F; + for (k = (int) ((width-1)*4); k >= 0; k -= 4) { + int digit = (int) ((value >> k) & 0x0F); if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) return 0; } diff --git a/src/loader.c b/src/loader.c index dea8ac42..af0f2ad4 100644 --- a/src/loader.c +++ b/src/loader.c @@ -541,4 +541,4 @@ yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event, (void)POP(parser, *ctx); return 1; -} \ No newline at end of file +} diff --git a/src/reader.c b/src/reader.c index f3ac54c2..399516fc 100644 --- a/src/reader.c +++ b/src/reader.c @@ -292,7 +292,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) return yaml_parser_set_reader_error(parser, "invalid Unicode character", - parser->offset, value); + parser->offset, (int) value); break; @@ -350,7 +350,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) if ((value & 0xFC00) == 0xDC00) return yaml_parser_set_reader_error(parser, "unexpected low surrogate area", - parser->offset, value); + parser->offset, (int) value); /* Check for a high surrogate area. */ @@ -380,7 +380,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) if ((value2 & 0xFC00) != 0xDC00) return yaml_parser_set_reader_error(parser, "expected low surrogate area", - parser->offset+2, value2); + parser->offset+2, (int) value2); /* Generate the value of the surrogate pair. */ @@ -415,7 +415,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) || (value >= 0x10000 && value <= 0x10FFFF))) return yaml_parser_set_reader_error(parser, "control characters are not allowed", - parser->offset, value); + parser->offset, (int) value); /* Move the raw pointers. */ @@ -426,25 +426,25 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) /* 0000 0000-0000 007F -> 0xxxxxxx */ if (value <= 0x7F) { - *(parser->buffer.last++) = value; + *(parser->buffer.last++) = (unsigned char) value; } /* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */ else if (value <= 0x7FF) { - *(parser->buffer.last++) = 0xC0 + (value >> 6); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); + *(parser->buffer.last++) = (unsigned char)(0xC0 + (value >> 6)); + *(parser->buffer.last++) = (unsigned char)(0x80 + (value & 0x3F)); } /* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */ else if (value <= 0xFFFF) { - *(parser->buffer.last++) = 0xE0 + (value >> 12); - *(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); + *(parser->buffer.last++) = (unsigned char)(0xE0 + (value >> 12)); + *(parser->buffer.last++) = (unsigned char)(0x80 + ((value >> 6) & 0x3F)); + *(parser->buffer.last++) = (unsigned char)(0x80 + (value & 0x3F)); } /* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ else { - *(parser->buffer.last++) = 0xF0 + (value >> 18); - *(parser->buffer.last++) = 0x80 + ((value >> 12) & 0x3F); - *(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); + *(parser->buffer.last++) = (unsigned char)(0xF0 + (value >> 18)); + *(parser->buffer.last++) = (unsigned char)(0x80 + ((value >> 12) & 0x3F)); + *(parser->buffer.last++) = (unsigned char)(0x80 + ((value >> 6) & 0x3F)); + *(parser->buffer.last++) = (unsigned char)(0x80 + (value & 0x3F)); } parser->unread ++; diff --git a/src/scanner.c b/src/scanner.c index c6b49876..6e0e37e7 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -882,7 +882,7 @@ yaml_parser_fetch_next_token(yaml_parser_t *parser) /* Check the indentation level against the current column. */ - if (!yaml_parser_unroll_indent(parser, parser->mark.column)) + if (!yaml_parser_unroll_indent(parser, (long) parser->mark.column)) return 0; /* @@ -1585,7 +1585,7 @@ yaml_parser_fetch_block_entry(yaml_parser_t *parser) /* Add the BLOCK-SEQUENCE-START token if needed. */ - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, + if (!yaml_parser_roll_indent(parser, (long) parser->mark.column, -1, YAML_BLOCK_SEQUENCE_START_TOKEN, parser->mark)) return 0; } @@ -1646,7 +1646,7 @@ yaml_parser_fetch_key(yaml_parser_t *parser) /* Add the BLOCK-MAPPING-START token if needed. */ - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, + if (!yaml_parser_roll_indent(parser, (long) parser->mark.column, -1, YAML_BLOCK_MAPPING_START_TOKEN, parser->mark)) return 0; } @@ -1702,8 +1702,8 @@ yaml_parser_fetch_value(yaml_parser_t *parser) /* In the block context, we may need to add the BLOCK-MAPPING-START token. */ - if (!yaml_parser_roll_indent(parser, simple_key->mark.column, - simple_key->token_number, + if (!yaml_parser_roll_indent(parser, (long) simple_key->mark.column, + (long) simple_key->token_number, YAML_BLOCK_MAPPING_START_TOKEN, simple_key->mark)) return 0; @@ -1732,7 +1732,7 @@ yaml_parser_fetch_value(yaml_parser_t *parser) /* Add the BLOCK-MAPPING-START token if needed. */ - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, + if (!yaml_parser_roll_indent(parser, (long) parser->mark.column, -1, YAML_BLOCK_MAPPING_START_TOKEN, parser->mark)) return 0; } @@ -2694,7 +2694,7 @@ yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, /* Get the octet. */ - octet = (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2); + octet = (unsigned char) (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2); /* If it is the leading octet, determine the length of the UTF-8 sequence. */ @@ -3249,22 +3249,22 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, } if (value <= 0x7F) { - *(string.pointer++) = value; + *(string.pointer++) = (unsigned char) value; } else if (value <= 0x7FF) { - *(string.pointer++) = 0xC0 + (value >> 6); - *(string.pointer++) = 0x80 + (value & 0x3F); + *(string.pointer++) = (unsigned char) (0xC0 + (value >> 6)); + *(string.pointer++) = (unsigned char) (0x80 + (value & 0x3F)); } else if (value <= 0xFFFF) { - *(string.pointer++) = 0xE0 + (value >> 12); - *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F); - *(string.pointer++) = 0x80 + (value & 0x3F); + *(string.pointer++) = (unsigned char) (0xE0 + (value >> 12)); + *(string.pointer++) = (unsigned char) (0x80 + ((value >> 6) & 0x3F)); + *(string.pointer++) = (unsigned char) (0x80 + (value & 0x3F)); } else { - *(string.pointer++) = 0xF0 + (value >> 18); - *(string.pointer++) = 0x80 + ((value >> 12) & 0x3F); - *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F); - *(string.pointer++) = 0x80 + (value & 0x3F); + *(string.pointer++) = (unsigned char) (0xF0 + (value >> 18)); + *(string.pointer++) = (unsigned char) (0x80 + ((value >> 12) & 0x3F)); + *(string.pointer++) = (unsigned char) (0x80 + ((value >> 6) & 0x3F)); + *(string.pointer++) = (unsigned char) (0x80 + (value & 0x3F)); } /* Advance the pointer. */ diff --git a/src/writer.c b/src/writer.c index 5d57f392..cc5e4371 100644 --- a/src/writer.c +++ b/src/writer.c @@ -104,8 +104,8 @@ yaml_emitter_flush(yaml_emitter_t *emitter) if (value < 0x10000) { - emitter->raw_buffer.last[high] = value >> 8; - emitter->raw_buffer.last[low] = value & 0xFF; + emitter->raw_buffer.last[high] = (unsigned char) (value >> 8); + emitter->raw_buffer.last[low] = (unsigned char) (value & 0xFF); emitter->raw_buffer.last += 2; } @@ -114,10 +114,10 @@ yaml_emitter_flush(yaml_emitter_t *emitter) /* Write the character using a surrogate pair (check "reader.c"). */ value -= 0x10000; - emitter->raw_buffer.last[high] = 0xD8 + (value >> 18); - emitter->raw_buffer.last[low] = (value >> 10) & 0xFF; - emitter->raw_buffer.last[high+2] = 0xDC + ((value >> 8) & 0xFF); - emitter->raw_buffer.last[low+2] = value & 0xFF; + emitter->raw_buffer.last[high] = (unsigned char) (0xD8 + (value >> 18)); + emitter->raw_buffer.last[low] = (unsigned char) ((value >> 10) & 0xFF); + emitter->raw_buffer.last[high+2] = (unsigned char) (0xDC + ((value >> 8) & 0xFF)); + emitter->raw_buffer.last[low+2] = (unsigned char) (value & 0xFF); emitter->raw_buffer.last += 4; } diff --git a/tests/example-deconstructor-alt.c b/tests/example-deconstructor-alt.c index b29c0777..5189326f 100644 --- a/tests/example-deconstructor-alt.c +++ b/tests/example-deconstructor-alt.c @@ -415,7 +415,7 @@ main(int argc, char *argv[]) if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, input_event.data.scalar.value, - input_event.data.scalar.length, + (int) input_event.data.scalar.length, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, diff --git a/tests/example-deconstructor.c b/tests/example-deconstructor.c index e048ee6b..78f22779 100644 --- a/tests/example-deconstructor.c +++ b/tests/example-deconstructor.c @@ -588,7 +588,7 @@ main(int argc, char *argv[]) if (!yaml_scalar_event_initialize(&output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", input_event.data.scalar.value, - input_event.data.scalar.length, + (int) input_event.data.scalar.length, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) diff --git a/tests/run-dumper.c b/tests/run-dumper.c index 04c5beea..ff4bccd9 100644 --- a/tests/run-dumper.c +++ b/tests/run-dumper.c @@ -29,7 +29,7 @@ int copy_document(yaml_document_t *document_to, yaml_document_t *document_from) switch (node->type) { case YAML_SCALAR_NODE: if (!yaml_document_add_scalar(document_to, node->tag, - node->data.scalar.value, node->data.scalar.length, + node->data.scalar.value, (int) node->data.scalar.length, node->data.scalar.style)) goto error; break; case YAML_SEQUENCE_NODE: diff --git a/tests/run-emitter-test-suite.c b/tests/run-emitter-test-suite.c index ba0f163a..395cc8a1 100644 --- a/tests/run-emitter-test-suite.c +++ b/tests/run-emitter-test-suite.c @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) style = YAML_FLOW_MAPPING_STYLE; ok = yaml_mapping_start_event_initialize(&event, (yaml_char_t *) get_anchor('&', line, anchor), (yaml_char_t *) - get_tag(line, tag), 0, style); + get_tag(line, tag), 0, (yaml_mapping_style_t) style); } else if (strncmp(line, "-MAP", 4) == 0) { ok = yaml_mapping_end_event_initialize(&event); @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) style = YAML_FLOW_SEQUENCE_STYLE; ok = yaml_sequence_start_event_initialize(&event, (yaml_char_t *) get_anchor('&', line, anchor), (yaml_char_t *) - get_tag(line, tag), 0, style); + get_tag(line, tag), 0, (yaml_sequence_style_t) style); } else if (strncmp(line, "-SEQ", 4) == 0) { ok = yaml_sequence_end_event_initialize(&event); @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) implicit = (get_tag(line, tag) == NULL); ok = yaml_scalar_event_initialize(&event, (yaml_char_t *) - get_anchor('&', line, anchor), (yaml_char_t *) get_tag(line, tag), (yaml_char_t *) value, -1, implicit, implicit, style); + get_anchor('&', line, anchor), (yaml_char_t *) get_tag(line, tag), (yaml_char_t *) value, -1, implicit, implicit, (yaml_scalar_style_t) style); } else if (strncmp(line, "=ALI", 4) == 0) { ok = yaml_alias_event_initialize(&event, (yaml_char_t *) diff --git a/tests/run-emitter.c b/tests/run-emitter.c index 3ffe4754..6b8aa6ba 100644 --- a/tests/run-emitter.c +++ b/tests/run-emitter.c @@ -43,7 +43,7 @@ int copy_event(yaml_event_t *event_to, yaml_event_t *event_from) event_from->data.scalar.anchor, event_from->data.scalar.tag, event_from->data.scalar.value, - event_from->data.scalar.length, + (int) event_from->data.scalar.length, event_from->data.scalar.plain_implicit, event_from->data.scalar.quoted_implicit, event_from->data.scalar.style);