diff --git a/src/api.c b/src/api.c index 16f88bd7..65d86a9b 100644 --- a/src/api.c +++ b/src/api.c @@ -120,8 +120,7 @@ yaml_stack_extend(void **start, void **top, void **end) { void *new_start; - if ((char *)*end - (char *)*start >= INT_MAX / 2) - return 0; + if ((char *)*end - (char *)*start >= INT_MAX / 2) return 0; new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); @@ -762,9 +761,9 @@ yaml_document_start_event_initialize(yaml_event_t *event, error: yaml_free(version_directive_copy); while (!STACK_EMPTY(context, tag_directives_copy)) { - yaml_tag_directive_t value = POP(context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); + yaml_tag_directive_t value_inner = POP(context, tag_directives_copy); + yaml_free(value_inner.handle); + yaml_free(value_inner.prefix); } STACK_DEL(context, tag_directives_copy); yaml_free(value.handle); @@ -1104,9 +1103,9 @@ yaml_document_initialize(yaml_document_t *document, STACK_DEL(&context, nodes); yaml_free(version_directive_copy); while (!STACK_EMPTY(&context, tag_directives_copy)) { - yaml_tag_directive_t value = POP(&context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); + yaml_tag_directive_t value_inner = POP(&context, tag_directives_copy); + yaml_free(value_inner.handle); + yaml_free(value_inner.prefix); } STACK_DEL(&context, tag_directives_copy); yaml_free(value.handle); @@ -1389,5 +1388,3 @@ yaml_document_append_mapping_pair(yaml_document_t *document, return 1; } - - diff --git a/src/emitter.c b/src/emitter.c index 609b28a4..42cb20f6 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -16,7 +16,7 @@ #define PUT(emitter,value) \ (FLUSH(emitter) \ && (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \ - emitter->column++, \ + emitter->column++, \ 1)) /* @@ -1895,15 +1895,15 @@ yaml_emitter_write_tag_content(yaml_emitter_t *emitter, } else { int width = WIDTH(string); - unsigned int value; + unsigned int value_inner = 0; while (width --) { - value = *(string.pointer++); + value_inner = *(string.pointer++); if (!PUT(emitter, '%')) return 0; - if (!PUT(emitter, (value >> 4) - + ((value >> 4) < 10 ? '0' : 'A' - 10))) + if (!PUT(emitter, (value_inner >> 4) + + ((value_inner >> 4) < 10 ? '0' : 'A' - 10))) return 0; - if (!PUT(emitter, (value & 0x0F) - + ((value & 0x0F) < 10 ? '0' : 'A' - 10))) + if (!PUT(emitter, (value_inner & 0x0F) + + ((value_inner & 0x0F) < 10 ? '0' : 'A' - 10))) return 0; } } @@ -2067,7 +2067,7 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, { unsigned char octet; unsigned int width; - unsigned int value; + unsigned int value_inner; int k; octet = string.pointer[0]; @@ -2075,19 +2075,19 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, (octet & 0xE0) == 0xC0 ? 2 : (octet & 0xF0) == 0xE0 ? 3 : (octet & 0xF8) == 0xF0 ? 4 : 0; - value = (octet & 0x80) == 0x00 ? octet & 0x7F : + value_inner = (octet & 0x80) == 0x00 ? octet & 0x7F : (octet & 0xE0) == 0xC0 ? octet & 0x1F : (octet & 0xF0) == 0xE0 ? octet & 0x0F : (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; for (k = 1; k < (int)width; k ++) { octet = string.pointer[k]; - value = (value << 6) + (octet & 0x3F); + value_inner = (value_inner << 6) + (octet & 0x3F); } string.pointer += width; if (!PUT(emitter, '\\')) return 0; - switch (value) + switch (value_inner) { case 0x00: if (!PUT(emitter, '0')) return 0; @@ -2150,11 +2150,11 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, break; default: - if (value <= 0xFF) { + if (value_inner <= 0xFF) { if (!PUT(emitter, 'x')) return 0; width = 2; } - else if (value <= 0xFFFF) { + else if (value_inner <= 0xFFFF) { if (!PUT(emitter, 'u')) return 0; width = 4; } @@ -2163,7 +2163,7 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, width = 8; } for (k = (width-1)*4; k >= 0; k -= 4) { - int digit = (value >> k) & 0x0F; + int digit = (value_inner >> k) & 0x0F; if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) return 0; } diff --git a/tests/run-dumper.c b/tests/run-dumper.c index 04c5beea..6347ae32 100644 --- a/tests/run-dumper.c +++ b/tests/run-dumper.c @@ -12,6 +12,12 @@ #define BUFFER_SIZE 65536 #define MAX_DOCUMENTS 16 +int copy_document(yaml_document_t *document_to, yaml_document_t *document_from); +int compare_nodes(yaml_document_t *document1, int index1, + yaml_document_t *document2, int index2, int level); +int compare_documents(yaml_document_t *document1, yaml_document_t *document2); +int print_output(char *name, unsigned char *buffer, size_t size, int count); + int copy_document(yaml_document_t *document_to, yaml_document_t *document_from) { yaml_node_t *node; @@ -236,7 +242,7 @@ main(int argc, char *argv[]) int done = 0; int count = 0; int error = 0; - int k; + size_t k; memset(buffer, 0, BUFFER_SIZE+1); memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t)); diff --git a/tests/run-emitter-test-suite.c b/tests/run-emitter-test-suite.c index ba0f163a..621e35a2 100644 --- a/tests/run-emitter-test-suite.c +++ b/tests/run-emitter-test-suite.c @@ -13,7 +13,7 @@ int usage(int ret); int main(int argc, char *argv[]) { - FILE *input; + FILE *input = stdin; yaml_emitter_t emitter; yaml_event_t event; yaml_version_directive_t *version_directive = NULL; @@ -66,9 +66,6 @@ int main(int argc, char *argv[]) version_directive->major = 1; version_directive->minor = minor; } - if (!foundfile) - input = stdin; - assert(input); if (!yaml_emitter_initialize(&emitter)) { @@ -129,13 +126,13 @@ int main(int argc, char *argv[]) } else if (strncmp(line, "=VAL", 4) == 0) { char value[1024]; - int style; + int style_inner; - get_value(line, value, &style); + get_value(line, value, &style_inner); 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, style_inner); } 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..5f27e6e2 100644 --- a/tests/run-emitter.c +++ b/tests/run-emitter.c @@ -12,6 +12,10 @@ #define BUFFER_SIZE 65536 #define MAX_EVENTS 1024 +int copy_event(yaml_event_t *event_to, yaml_event_t *event_from); +int compare_events(yaml_event_t *event1, yaml_event_t *event2); +int print_output(char *name, unsigned char *buffer, size_t size, int count); + int copy_event(yaml_event_t *event_to, yaml_event_t *event_from) { switch (event_from->type) @@ -258,7 +262,7 @@ main(int argc, char *argv[]) int done = 0; int count = 0; int error = 0; - int k; + size_t k; memset(buffer, 0, BUFFER_SIZE+1); memset(events, 0, MAX_EVENTS*sizeof(yaml_event_t)); diff --git a/tests/run-parser-test-suite.c b/tests/run-parser-test-suite.c index 5bdd6623..57a90094 100644 --- a/tests/run-parser-test-suite.c +++ b/tests/run-parser-test-suite.c @@ -8,7 +8,7 @@ int usage(int ret); int main(int argc, char *argv[]) { - FILE *input; + FILE *input = stdin; yaml_parser_t parser; yaml_event_t event; int flow = -1; /** default no flow style collections */ @@ -40,9 +40,6 @@ int main(int argc, char *argv[]) else return usage(1); } - if (!foundfile) { - input = stdin; - } assert(input); if (!yaml_parser_initialize(&parser)) { @@ -161,7 +158,7 @@ int main(int argc, char *argv[]) void print_escaped(yaml_char_t * str, size_t length) { - int i; + size_t i; char c; for (i = 0; i < length; i++) { diff --git a/tests/test-reader.c b/tests/test-reader.c index 40f8199e..79dc6ebd 100644 --- a/tests/test-reader.c +++ b/tests/test-reader.c @@ -114,6 +114,11 @@ test_case boms[] = { char *bom_original = "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82"; +int check_utf8_sequences(void); +int check_boms(void); +int check_long_utf8(void); +int check_long_utf16(void); + int check_utf8_sequences(void) { yaml_parser_t parser; @@ -184,7 +189,7 @@ int check_boms(void) failed++; } else { - if (parser.unread != check) { + if (check >= 0 && (size_t)check != parser.unread) { printf("- (length=%ld while expected length=%d)\n", (long)parser.unread, check); failed++; }