]> andersk Git - libyaml.git/blobdiff - src/scanner.c
spec-1.2 rule [53]
[libyaml.git] / src / scanner.c
index 1414401d47013bcd711ceac0a3735f4cb062f75a..3f7f2acf48acb95a2e646e54034935bd46f76f84 100644 (file)
@@ -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.
@@ -1078,7 +1078,7 @@ yaml_parser_stale_simple_keys(yaml_parser_t *parser)
             if (simple_key->required) {
                 return yaml_parser_set_scanner_error(parser,
                         "while scanning a simple key", simple_key->mark,
-                        "could not found expected ':'");
+                        "could not find expected ':'");
             }
 
             simple_key->possible = 0;
@@ -1103,14 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
      */
 
     int required = (!parser->flow_level
-            && parser->indent == parser->mark.column);
-
-    /*
-     * A simple key is required only when it is the first token in the current
-     * line.  Therefore it is always allowed.  But we add a check anyway.
-     */
-
-    assert(parser->simple_key_allowed || !required);    /* Impossible. */
+            && parser->indent == (ptrdiff_t)parser->mark.column);
 
     /*
      * If the current position may start a simple key, save it.
@@ -1118,9 +1111,12 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
 
     if (parser->simple_key_allowed)
     {
-        yaml_simple_key_t simple_key = { 1, required,
-            parser->tokens_parsed + parser->tokens.tail - parser->tokens.head,
-            parser->mark };
+        yaml_simple_key_t simple_key;
+        simple_key.possible = 1;
+        simple_key.required = required;
+        simple_key.token_number = 
+            parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head);
+        simple_key.mark = parser->mark;
 
         if (!yaml_parser_remove_simple_key(parser)) return 0;
 
@@ -1146,7 +1142,7 @@ yaml_parser_remove_simple_key(yaml_parser_t *parser)
         if (simple_key->required) {
             return yaml_parser_set_scanner_error(parser,
                     "while scanning a simple key", simple_key->mark,
-                    "could not found expected ':'");
+                    "could not find expected ':'");
         }
     }
 
@@ -1173,6 +1169,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;
@@ -1185,9 +1186,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
 static int
 yaml_parser_decrease_flow_level(yaml_parser_t *parser)
 {
+    yaml_simple_key_t dummy_key;    /* Used to eliminate a compiler warning. */
+
     if (parser->flow_level) {
         parser->flow_level --;
-        POP(parser, parser->simple_keys);
+        dummy_key = POP(parser, parser->simple_keys);
     }
 
     return 1;
@@ -1201,8 +1204,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;
 
@@ -1221,6 +1224,11 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
         if (!PUSH(parser, parser->indents, parser->indent))
             return 0;
 
+        if (column > INT_MAX) {
+            parser->error = YAML_MEMORY_ERROR;
+            return 0;
+        }
+
         parser->indent = column;
 
         /* Create a token and insert it into the queue. */
@@ -1249,7 +1257,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
 
 
 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;
 
@@ -1324,6 +1332,13 @@ yaml_parser_fetch_stream_end(yaml_parser_t *parser)
 {
     yaml_token_t token;
 
+    /* Force new line. */
+
+    if (parser->mark.column != 0) {
+        parser->mark.column = 0;
+        parser->mark.line ++;
+    }
+
     /* Reset the indentation level. */
 
     if (!yaml_parser_unroll_indent(parser, -1))
@@ -2062,7 +2077,7 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token)
 
     if (!IS_BREAKZ(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a directive",
-                start_mark, "did not found expected comment or line break");
+                start_mark, "did not find expected comment or line break");
         goto error;
     }
 
@@ -2116,7 +2131,7 @@ yaml_parser_scan_directive_name(yaml_parser_t *parser,
 
     if (string.start == string.pointer) {
         yaml_parser_set_scanner_error(parser, "while scanning a directive",
-                start_mark, "cannot found expected directive name");
+                start_mark, "could not find expected directive name");
         goto error;
     }
 
@@ -2462,7 +2477,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
 
     if (!IS_BLANKZ(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a tag",
-                start_mark, "did not found expected whitespace or line break");
+                start_mark, "did not find expected whitespace or line break");
         goto error;
     }
 
@@ -2562,7 +2577,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
 
     /* Resize the string to include the head. */
 
-    while (string.end - string.start <= 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;
@@ -2607,6 +2622,9 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
         /* Check if it is a URI-escape sequence. */
 
         if (CHECK(parser->buffer, '%')) {
+            if (!STRING_EXTEND(parser, string))
+                goto error;
+
             if (!yaml_parser_scan_uri_escapes(parser,
                         directive, start_mark, &string)) goto error;
         }
@@ -2816,7 +2834,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     if (!IS_BREAKZ(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
-                start_mark, "did not found expected comment or line break");
+                start_mark, "did not find expected comment or line break");
         goto error;
     }
 
@@ -2844,7 +2862,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (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.
@@ -2951,18 +2969,18 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
 
         if (!CACHE(parser, 1)) return 0;
 
-        while ((!*indent || parser->mark.column < *indent)
+        while ((!*indent || (int)parser->mark.column < *indent)
                 && IS_SPACE(parser->buffer)) {
             SKIP(parser);
             if (!CACHE(parser, 1)) return 0;
         }
 
-        if (parser->mark.column > max_indent)
-            max_indent = parser->mark.column;
+        if ((int)parser->mark.column > max_indent)
+            max_indent = (int)parser->mark.column;
 
         /* Check for a tab character messing the intendation. */
 
-        if ((!*indent || parser->mark.column < *indent)
+        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 intendation space is expected");
@@ -3091,7 +3109,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
             else if (!single && CHECK(parser->buffer, '\\'))
             {
-                int code_length = 0;
+                size_t code_length = 0;
 
                 if (!STRING_EXTEND(parser, string)) goto error;
 
@@ -3144,6 +3162,10 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
                         *(string.pointer++) = '"';
                         break;
 
+                    case '/':
+                        *(string.pointer++) = '/';
+                        break;
+
                     case '\'':
                         *(string.pointer++) = '\'';
                         break;
@@ -3200,7 +3222,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
                 if (code_length)
                 {
                     unsigned int value = 0;
-                    int k;
+                    size_t k;
 
                     /* Scan the character value. */
 
@@ -3488,7 +3510,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
             {
                 /* Check for tab character that abuse intendation. */
 
-                if (leading_blanks && parser->mark.column < indent
+                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 violate intendation");
@@ -3526,7 +3548,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
 
         /* Check intendation level. */
 
-        if (!parser->flow_level && parser->mark.column < indent)
+        if (!parser->flow_level && (int)parser->mark.column < indent)
             break;
     }
 
This page took 0.046438 seconds and 4 git commands to generate.