Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a patch from Jakub Maly. #274

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ yaml_strdup(const yaml_char_t *str)
if (!str)
return NULL;

#if defined (_WIN32)
return (yaml_char_t *)_strdup((char *)str);
#else
return (yaml_char_t *)strdup((char *)str);
#endif
}

/*
Expand Down Expand Up @@ -120,8 +124,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);

Expand Down Expand Up @@ -762,9 +765,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);
Expand Down Expand Up @@ -1104,9 +1107,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);
Expand Down Expand Up @@ -1389,5 +1392,3 @@ yaml_document_append_mapping_pair(yaml_document_t *document,

return 1;
}


28 changes: 14 additions & 14 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define PUT(emitter,value) \
(FLUSH(emitter) \
&& (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \
emitter->column++, \
emitter->column++, \
1))

/*
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -2067,27 +2067,27 @@ 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];
width = (octet & 0x80) == 0x00 ? 1 :
(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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/run-dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
11 changes: 4 additions & 7 deletions tests/run-emitter-test-suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 *)
Expand Down
6 changes: 5 additions & 1 deletion tests/run-emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));

Expand Down
7 changes: 2 additions & 5 deletions tests/run-parser-test-suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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++) {
Expand Down
7 changes: 6 additions & 1 deletion tests/test-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
Expand Down