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

Cherry-picks from PR 27 #125

Merged
merged 6 commits into from
Jul 19, 2018
Merged
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: 13 additions & 8 deletions include/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,18 @@ typedef enum yaml_emitter_state_e {
YAML_EMIT_END_STATE
} yaml_emitter_state_t;


/* This is needed for C++ */

typedef struct yaml_anchors_s {
/** The number of references. */
int references;
/** The anchor id. */
int anchor;
/** If the node has been emitted? */
int serialized;
} yaml_anchors_t;

/**
* The emitter structure.
*
Expand Down Expand Up @@ -1742,14 +1754,7 @@ typedef struct yaml_emitter_s {
int closed;

/** The information associated with the document nodes. */
struct {
/** The number of references. */
int references;
/** The anchor id. */
int anchor;
/** If the node has been emitted? */
int serialized;
} *anchors;
yaml_anchors_t *anchors;

/** The last assigned anchor id. */
int last_anchor_id;
Expand Down
7 changes: 6 additions & 1 deletion src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ yaml_string_join(
YAML_DECLARE(int)
yaml_stack_extend(void **start, void **top, void **end)
{
void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);
void *new_start;

if ((char *)*end - (char *)*start >= INT_MAX / 2)
return 0;

new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);

if (!new_start) return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)

assert(emitter->opened); /* Emitter should be opened. */

emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors))
* (document->nodes.top - document->nodes.start));
if (!emitter->anchors) goto error;
memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
Expand Down
8 changes: 4 additions & 4 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 @@ -221,7 +221,7 @@ yaml_emitter_write_indent(yaml_emitter_t *emitter);

static int
yaml_emitter_write_indicator(yaml_emitter_t *emitter,
char *indicator, int need_whitespace,
const char *indicator, int need_whitespace,
int is_whitespace, int is_indention);

static int
Expand Down Expand Up @@ -1777,7 +1777,7 @@ yaml_emitter_write_indent(yaml_emitter_t *emitter)

static int
yaml_emitter_write_indicator(yaml_emitter_t *emitter,
char *indicator, int need_whitespace,
const char *indicator, int need_whitespace,
int is_whitespace, int is_indention)
{
size_t indicator_length;
Expand Down Expand Up @@ -2174,7 +2174,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
yaml_string_t string)
{
char indent_hint[2];
char *chomp_hint = NULL;
const char *chomp_hint = NULL;

if (IS_SPACE(string) || IS_BREAK(string))
{
Expand Down
2 changes: 2 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,8 @@ yaml_parser_process_directives(yaml_parser_t *parser,
STACK_DEL(parser, tag_directives);
}

if (!version_directive_ref)
yaml_free(version_directive);
return 1;

error:
Expand Down
2 changes: 1 addition & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,

if (!CACHE(parser, 1)) goto error;

while ((int)parser->mark.column == indent && !IS_Z(parser->buffer))
while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer)))
{
/*
* We are at the beginning of a non-empty line.
Expand Down
4 changes: 2 additions & 2 deletions src/yaml_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ yaml_string_join(
* Check the octet at the specified position.
*/

#define CHECK_AT(string,octet,offset) \
#define CHECK_AT(string,octet,offset) \
((string).pointer[offset] == (yaml_char_t)(octet))

/*
* Check the current octet in the buffer.
*/

#define CHECK(string,octet) CHECK_AT((string),(octet),0)
#define CHECK(string,octet) (CHECK_AT((string),(octet),0))

/*
* Check if the character at the specified position is an alphabetical
Expand Down