summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-02-05 12:09:50 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-02-05 12:09:50 -0800
commit4a86bfe4a2746c12fbc0210ab3f60cb2e30b6363 (patch)
tree99f9c2dbe5e2bbc990cb3db44114136b4415df2b /ext
parent3fac88a4b26793039fe098523d80166c740fd0e2 (diff)
downloadpsych-4a86bfe4a2746c12fbc0210ab3f60cb2e30b6363.zip
merge from ruby trunk
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/yaml/api.c53
-rw-r--r--ext/psych/yaml/emitter.c14
-rw-r--r--ext/psych/yaml/loader.c21
-rw-r--r--ext/psych/yaml/parser.c2
-rw-r--r--ext/psych/yaml/reader.c6
-rw-r--r--ext/psych/yaml/scanner.c14
-rw-r--r--ext/psych/yaml/writer.c2
-rw-r--r--ext/psych/yaml/yaml_private.h7
8 files changed, 81 insertions, 38 deletions
diff --git a/ext/psych/yaml/api.c b/ext/psych/yaml/api.c
index 0c4732e..1b6edc9 100644
--- a/ext/psych/yaml/api.c
+++ b/ext/psych/yaml/api.c
@@ -822,6 +822,7 @@ yaml_scalar_event_initialize(yaml_event_t *event,
yaml_char_t *anchor_copy = NULL;
yaml_char_t *tag_copy = NULL;
yaml_char_t *value_copy = NULL;
+ size_t value_length;
assert(event); /* Non-NULL event object is expected. */
assert(value); /* Non-NULL anchor is expected. */
@@ -839,16 +840,19 @@ yaml_scalar_event_initialize(yaml_event_t *event,
}
if (length < 0) {
- length = strlen((char *)value);
+ value_length = strlen((char *)value);
+ }
+ else {
+ value_length = (size_t)length;
}
- if (!yaml_check_utf8(value, length)) goto error;
- value_copy = yaml_malloc(length+1);
+ if (!yaml_check_utf8(value, value_length)) goto error;
+ value_copy = yaml_malloc(value_length+1);
if (!value_copy) goto error;
- memcpy(value_copy, value, length);
- value_copy[length] = '\0';
+ memcpy(value_copy, value, value_length);
+ value_copy[value_length] = '\0';
- SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length,
+ SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, value_length,
plain_implicit, quoted_implicit, style, mark, mark);
return 1;
@@ -1202,6 +1206,8 @@ yaml_document_add_scalar(yaml_document_t *document,
yaml_char_t *tag_copy = NULL;
yaml_char_t *value_copy = NULL;
yaml_node_t node;
+ size_t value_length;
+ ptrdiff_t ret;
assert(document); /* Non-NULL document object is expected. */
assert(value); /* Non-NULL value is expected. */
@@ -1215,19 +1221,26 @@ yaml_document_add_scalar(yaml_document_t *document,
if (!tag_copy) goto error;
if (length < 0) {
- length = strlen((char *)value);
+ value_length = strlen((char *)value);
+ }
+ else {
+ value_length = (size_t)length;
}
- if (!yaml_check_utf8(value, length)) goto error;
- value_copy = yaml_malloc(length+1);
+ if (!yaml_check_utf8(value, value_length)) goto error;
+ value_copy = yaml_malloc(value_length+1);
if (!value_copy) goto error;
- memcpy(value_copy, value, length);
- value_copy[length] = '\0';
+ memcpy(value_copy, value, value_length);
+ value_copy[value_length] = '\0';
- SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark);
+ SCALAR_NODE_INIT(node, tag_copy, value_copy, value_length, style, mark, mark);
if (!PUSH(&context, document->nodes, node)) goto error;
- return document->nodes.top - document->nodes.start;
+ ret = document->nodes.top - document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (ret > INT_MAX) goto error;
+#endif
+ return (int)ret;
error:
yaml_free(tag_copy);
@@ -1255,6 +1268,7 @@ yaml_document_add_sequence(yaml_document_t *document,
yaml_node_item_t *top;
} items = { NULL, NULL, NULL };
yaml_node_t node;
+ ptrdiff_t ret;
assert(document); /* Non-NULL document object is expected. */
@@ -1272,7 +1286,11 @@ yaml_document_add_sequence(yaml_document_t *document,
style, mark, mark);
if (!PUSH(&context, document->nodes, node)) goto error;
- return document->nodes.top - document->nodes.start;
+ ret = document->nodes.top - document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (ret > INT_MAX) goto error;
+#endif
+ return (int)ret;
error:
STACK_DEL(&context, items);
@@ -1300,6 +1318,7 @@ yaml_document_add_mapping(yaml_document_t *document,
yaml_node_pair_t *top;
} pairs = { NULL, NULL, NULL };
yaml_node_t node;
+ ptrdiff_t ret;
assert(document); /* Non-NULL document object is expected. */
@@ -1317,7 +1336,11 @@ yaml_document_add_mapping(yaml_document_t *document,
style, mark, mark);
if (!PUSH(&context, document->nodes, node)) goto error;
- return document->nodes.top - document->nodes.start;
+ ret = document->nodes.top - document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (ret > INT_MAX) goto error;
+#endif
+ return (int)ret;
error:
STACK_DEL(&context, pairs);
diff --git a/ext/psych/yaml/emitter.c b/ext/psych/yaml/emitter.c
index c4b56a2..c852f93 100644
--- a/ext/psych/yaml/emitter.c
+++ b/ext/psych/yaml/emitter.c
@@ -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
@@ -517,7 +517,7 @@ yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
if (emitter->best_width < 0) {
emitter->best_width = INT_MAX;
}
-
+
if (!emitter->line_break) {
emitter->line_break = YAML_LN_BREAK;
}
@@ -607,7 +607,7 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
if (!yaml_emitter_write_indent(emitter))
return 0;
}
-
+
if (event->data.document_start.tag_directives.start
!= event->data.document_start.tag_directives.end) {
implicit = 0;
@@ -721,7 +721,7 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
}
/*
- *
+ *
* Expect a flow item node.
*/
@@ -1402,7 +1402,7 @@ yaml_emitter_analyze_anchor(yaml_emitter_t *emitter,
{
size_t anchor_length;
yaml_string_t string;
-
+
anchor_length = strlen((char *)anchor);
STRING_ASSIGN(string, anchor, anchor_length);
@@ -1784,7 +1784,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;
@@ -2178,7 +2178,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))
{
diff --git a/ext/psych/yaml/loader.c b/ext/psych/yaml/loader.c
index 871149a..cb3ea93 100644
--- a/ext/psych/yaml/loader.c
+++ b/ext/psych/yaml/loader.c
@@ -283,6 +283,7 @@ static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_node_t node;
+ ptrdiff_t node_index;
int index;
yaml_char_t *tag = first_event->data.scalar.tag;
@@ -300,7 +301,11 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
if (!PUSH(parser, parser->document->nodes, node)) goto error;
- index = parser->document->nodes.top - parser->document->nodes.start;
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (node_index > INT_MAX) goto error;
+#endif
+ index = (int)node_index;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.scalar.anchor)) return 0;
@@ -329,6 +334,7 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_node_item_t *top;
} items = { NULL, NULL, NULL };
int index, item_index;
+ ptrdiff_t node_index;
yaml_char_t *tag = first_event->data.sequence_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@@ -347,7 +353,11 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
if (!PUSH(parser, parser->document->nodes, node)) goto error;
- index = parser->document->nodes.top - parser->document->nodes.start;
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (node_index > INT_MAX) goto error;
+#endif
+ index = (int)node_index;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.sequence_start.anchor)) return 0;
@@ -391,6 +401,7 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_node_pair_t *top;
} pairs = { NULL, NULL, NULL };
int index;
+ ptrdiff_t node_index;
yaml_node_pair_t pair;
yaml_char_t *tag = first_event->data.mapping_start.tag;
@@ -410,7 +421,11 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
if (!PUSH(parser, parser->document->nodes, node)) goto error;
- index = parser->document->nodes.top - parser->document->nodes.start;
+ node_index = parser->document->nodes.top - parser->document->nodes.start;
+#if PTRDIFF_MAX > INT_MAX
+ if (node_index > INT_MAX) goto error;
+#endif
+ index = (int)node_index;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.mapping_start.anchor)) return 0;
diff --git a/ext/psych/yaml/parser.c b/ext/psych/yaml/parser.c
index eb2a2c7..dc5430b 100644
--- a/ext/psych/yaml/parser.c
+++ b/ext/psych/yaml/parser.c
@@ -1295,7 +1295,7 @@ yaml_parser_process_directives(yaml_parser_t *parser,
token = PEEK_TOKEN(parser);
if (!token) goto error;
}
-
+
for (default_tag_directive = default_tag_directives;
default_tag_directive->handle; default_tag_directive++) {
if (!yaml_parser_append_tag_directive(parser, *default_tag_directive, 1,
diff --git a/ext/psych/yaml/reader.c b/ext/psych/yaml/reader.c
index d47921c..f1a06de 100644
--- a/ext/psych/yaml/reader.c
+++ b/ext/psych/yaml/reader.c
@@ -52,7 +52,7 @@ yaml_parser_determine_encoding(yaml_parser_t *parser)
{
/* Ensure that we had enough bytes in the raw buffer. */
- while (!parser->eof
+ while (!parser->eof
&& parser->raw_buffer.last - parser->raw_buffer.pointer < 3) {
if (!yaml_parser_update_raw_buffer(parser)) {
return 0;
@@ -295,7 +295,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
parser->offset, value);
break;
-
+
case YAML_UTF16LE_ENCODING:
case YAML_UTF16BE_ENCODING:
@@ -318,7 +318,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
*
* The following formulas are used for decoding
* and encoding characters using surrogate pairs:
- *
+ *
* U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF)
* U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF)
* W1 = 110110yyyyyyyyyy
diff --git a/ext/psych/yaml/scanner.c b/ext/psych/yaml/scanner.c
index ea1a941..2ca3fed 100644
--- a/ext/psych/yaml/scanner.c
+++ b/ext/psych/yaml/scanner.c
@@ -762,7 +762,7 @@ yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token)
}
/* Fetch the next token from the queue. */
-
+
*token = DEQUEUE(parser, parser->tokens);
parser->token_available = 0;
parser->tokens_parsed ++;
@@ -1121,7 +1121,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
yaml_simple_key_t simple_key;
simple_key.possible = 1;
simple_key.required = required;
- simple_key.token_number =
+ simple_key.token_number =
parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head);
simple_key.mark = parser->mark;
@@ -1207,7 +1207,7 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
* Push the current indentation level to the stack and set the new level
* the current column is greater than the indentation level. In this case,
* append or insert the specified token into the token queue.
- *
+ *
*/
static int
@@ -1231,12 +1231,14 @@ yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
if (!PUSH(parser, parser->indents, parser->indent))
return 0;
+#if PTRDIFF_MAX > INT_MAX
if (column > INT_MAX) {
parser->error = YAML_MEMORY_ERROR;
return 0;
}
+#endif
- parser->indent = column;
+ parser->indent = (int)column;
/* Create a token and insert it into the queue. */
@@ -1945,7 +1947,7 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser)
*
* - in the flow context;
* - in the block context, but not at the beginning of the line or
- * after '-', '?', or ':' (complex value).
+ * after '-', '?', or ':' (complex value).
*/
if (!CACHE(parser, 1)) return 0;
@@ -3011,7 +3013,7 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
*indent = 1;
}
- return 1;
+ return 1;
}
/*
diff --git a/ext/psych/yaml/writer.c b/ext/psych/yaml/writer.c
index b90019f..5d57f39 100644
--- a/ext/psych/yaml/writer.c
+++ b/ext/psych/yaml/writer.c
@@ -74,7 +74,7 @@ yaml_emitter_flush(yaml_emitter_t *emitter)
unsigned int value;
size_t k;
- /*
+ /*
* See the "reader.c" code for more details on UTF-8 encoding. Note
* that we assume that the buffer contains a valid UTF-8 sequence.
*/
diff --git a/ext/psych/yaml/yaml_private.h b/ext/psych/yaml/yaml_private.h
index 9589e05..21fc5e4 100644
--- a/ext/psych/yaml/yaml_private.h
+++ b/ext/psych/yaml/yaml_private.h
@@ -1,3 +1,6 @@
+#ifdef RUBY_EXTCONF_H
+#include RUBY_EXTCONF_H
+#endif
#if HAVE_CONFIG_H
#include <config.h>
@@ -239,9 +242,9 @@ yaml_string_join(
(string).pointer[offset] <= (yaml_char_t) 'f') ? \
((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
((string).pointer[offset] - (yaml_char_t) '0'))
-
+
#define AS_HEX(string) AS_HEX_AT((string),0)
-
+
/*
* Check if the character is ASCII.
*/