summaryrefslogtreecommitdiff
path: root/ext/psych/yaml/scanner.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/psych/yaml/scanner.c')
-rw-r--r--ext/psych/yaml/scanner.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/ext/psych/yaml/scanner.c b/ext/psych/yaml/scanner.c
index 31fed0ed94..b87ad6f948 100644
--- a/ext/psych/yaml/scanner.c
+++ b/ext/psych/yaml/scanner.c
@@ -615,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser);
*/
static int
-yaml_parser_roll_indent(yaml_parser_t *parser, int column,
- int number, yaml_token_type_t type, yaml_mark_t mark);
+yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
+ ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark);
static int
-yaml_parser_unroll_indent(yaml_parser_t *parser, int column);
+yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column);
/*
* Token fetchers.
@@ -1103,7 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
*/
int required = (!parser->flow_level
- && parser->indent == (int)parser->mark.column);
+ && parser->indent == (ptrdiff_t)parser->mark.column);
/*
* A simple key is required only when it is the first token in the current
@@ -1176,6 +1176,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
/* Increase the flow level. */
+ if (parser->flow_level == INT_MAX) {
+ parser->error = YAML_MEMORY_ERROR;
+ return 0;
+ }
+
parser->flow_level++;
return 1;
@@ -1206,8 +1211,8 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
*/
static int
-yaml_parser_roll_indent(yaml_parser_t *parser, int column,
- int number, yaml_token_type_t type, yaml_mark_t mark)
+yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
+ ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark)
{
yaml_token_t token;
@@ -1226,7 +1231,14 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
if (!PUSH(parser, parser->indents, parser->indent))
return 0;
- parser->indent = column;
+#if PTRDIFF_MAX > INT_MAX
+ if (column > INT_MAX) {
+ parser->error = YAML_MEMORY_ERROR;
+ return 0;
+ }
+#endif
+
+ parser->indent = (int)column;
/* Create a token and insert it into the queue. */
@@ -1248,13 +1260,13 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
/*
* Pop indentation levels from the indents stack until the current level
- * becomes less or equal to the column. For each indentation level, append
+ * becomes less or equal to the column. For each intendation level, append
* the BLOCK-END token.
*/
static int
-yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
+yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column)
{
yaml_token_t token;
@@ -1263,7 +1275,7 @@ yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
if (parser->flow_level)
return 1;
- /* Loop through the indentation levels in the stack. */
+ /* Loop through the intendation levels in the stack. */
while (parser->indent > column)
{
@@ -2574,7 +2586,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
/* Resize the string to include the head. */
- while (string.end - string.start <= (int)length) {
+ while ((size_t)(string.end - string.start) <= length) {
if (!yaml_string_extend(&string.start, &string.pointer, &string.end)) {
parser->error = YAML_MEMORY_ERROR;
goto error;
@@ -2769,15 +2781,15 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
if (IS_DIGIT(parser->buffer))
{
- /* Check that the indentation is greater than 0. */
+ /* Check that the intendation is greater than 0. */
if (CHECK(parser->buffer, '0')) {
yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
- start_mark, "found an indentation indicator equal to 0");
+ start_mark, "found an intendation indicator equal to 0");
goto error;
}
- /* Get the indentation level and eat the indicator. */
+ /* Get the intendation level and eat the indicator. */
increment = AS_DIGIT(parser->buffer);
@@ -2791,7 +2803,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
{
if (CHECK(parser->buffer, '0')) {
yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
- start_mark, "found an indentation indicator equal to 0");
+ start_mark, "found an intendation indicator equal to 0");
goto error;
}
@@ -2841,7 +2853,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
end_mark = parser->mark;
- /* Set the indentation level if it was specified. */
+ /* Set the intendation level if it was specified. */
if (increment) {
indent = parser->indent >= 0 ? parser->indent+increment : increment;
@@ -2907,7 +2919,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
if (!READ_LINE(parser, leading_break)) goto error;
- /* Eat the following indentation spaces and line breaks. */
+ /* Eat the following intendation spaces and line breaks. */
if (!yaml_parser_scan_block_scalar_breaks(parser,
&indent, &trailing_breaks, start_mark, &end_mark)) goto error;
@@ -2942,8 +2954,8 @@ error:
}
/*
- * Scan indentation spaces and line breaks for a block scalar. Determine the
- * indentation level if needed.
+ * Scan intendation spaces and line breaks for a block scalar. Determine the
+ * intendation level if needed.
*/
static int
@@ -2955,11 +2967,11 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
*end_mark = parser->mark;
- /* Eat the indentation spaces and line breaks. */
+ /* Eat the intendation spaces and line breaks. */
while (1)
{
- /* Eat the indentation spaces. */
+ /* Eat the intendation spaces. */
if (!CACHE(parser, 1)) return 0;
@@ -2972,12 +2984,12 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
if ((int)parser->mark.column > max_indent)
max_indent = (int)parser->mark.column;
- /* Check for a tab character messing the indentation. */
+ /* Check for a tab character messing the intendation. */
if ((!*indent || (int)parser->mark.column < *indent)
&& IS_TAB(parser->buffer)) {
return yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
- start_mark, "found a tab character where an indentation space is expected");
+ start_mark, "found a tab character where an intendation space is expected");
}
/* Have we found a non-empty line? */
@@ -3498,12 +3510,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
{
if (IS_BLANK(parser->buffer))
{
- /* Check for tab character that abuse indentation. */
+ /* Check for tab character that abuse intendation. */
if (leading_blanks && (int)parser->mark.column < indent
&& IS_TAB(parser->buffer)) {
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
- start_mark, "found a tab character that violates indentation");
+ start_mark, "found a tab character that violate intendation");
goto error;
}
@@ -3536,7 +3548,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
if (!CACHE(parser, 1)) goto error;
}
- /* Check indentation level. */
+ /* Check intendation level. */
if (!parser->flow_level && (int)parser->mark.column < indent)
break;