]> andersk Git - libyaml.git/blobdiff - src/scanner.c
Fix typo error
[libyaml.git] / src / scanner.c
index bb811276cdb901a4b7423d9be5037082139b85aa..24e92c18fa1caba17d647a82059ec61038bc9a6d 100644 (file)
@@ -38,8 +38,8 @@
  *      BLOCK-END                       # Indentation decrease.
  *      FLOW-SEQUENCE-START             # '['
  *      FLOW-SEQUENCE-END               # ']'
- *      BLOCK-SEQUENCE-START            # '{'
- *      BLOCK-SEQUENCE-END              # '}'
+ *      FLOW-MAPPING-START              # '{'
+ *      FLOW-MAPPING-END                # '}'
  *      BLOCK-ENTRY                     # '-'
  *      FLOW-ENTRY                      # ','
  *      KEY                             # '?' or nothing (simple keys).
@@ -70,7 +70,7 @@
  *      %TAG    !yaml!  tag:yaml.org,2002:
  *      ---
  *
- * The correspoding sequence of tokens:
+ * The corresponding sequence of tokens:
  *
  *      STREAM-START(utf-8)
  *      VERSION-DIRECTIVE(1,1)
         ? 1                                                                     \
         : yaml_parser_update_buffer(parser, (length)))
 
-/*
- * Check the octet at the specified position.
- */
-
-#define CHECK_AT(parser,octet,offset)                                           \
-    (parser->buffer.pointer[offset] == (yaml_char_t)(octet))
-
-/*
- * Check the current octet in the buffer.
- */
-
-#define CHECK(parser,octet) CHECK_AT(parser,(octet),0)
-
-/*
- * Check if the character at the specified position is an alphabetical
- * character, a digit, '_', or '-'.
- */
-
-#define IS_ALPHA_AT(parser,offset)                                              \
-     ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) '9') ||                  \
-      (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) 'Z') ||                  \
-      (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) 'z') ||                  \
-      parser->buffer.pointer[offset] == '_' ||                                  \
-      parser->buffer.pointer[offset] == '-')
-
-#define IS_ALPHA(parser)    IS_ALPHA_AT(parser,0)
-
-/*
- * Check if the character at the specified position is a digit.
- */
-
-#define IS_DIGIT_AT(parser,offset)                                              \
-     ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) '9'))
-
-#define IS_DIGIT(parser)    IS_DIGIT_AT(parser,0)
-
-/*
- * Get the value of a digit.
- */
-
-#define AS_DIGIT_AT(parser,offset)                                              \
-     (parser->buffer.pointer[offset] - (yaml_char_t) '0')
-
-#define AS_DIGIT(parser)    AS_DIGIT_AT(parser,0)
-
-/*
- * Check if the character at the specified position is a hex-digit.
- */
-
-#define IS_HEX_AT(parser,offset)                                                \
-     ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) '9') ||                  \
-      (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) 'F') ||                  \
-      (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' &&                   \
-       parser->buffer.pointer[offset] <= (yaml_char_t) 'f'))
-
-#define IS_HEX(parser)    IS_HEX_AT(parser,0)
-
-/*
- * Get the value of a hex-digit.
- */
-
-#define AS_HEX_AT(parser,offset)                                                \
-      ((parser->buffer.pointer[offset] >= (yaml_char_t) 'A' &&                  \
-        parser->buffer.pointer[offset] <= (yaml_char_t) 'F') ?                  \
-       (parser->buffer.pointer[offset] - (yaml_char_t) 'A' + 10) :              \
-       (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' &&                  \
-        parser->buffer.pointer[offset] <= (yaml_char_t) 'f') ?                  \
-       (parser->buffer.pointer[offset] - (yaml_char_t) 'a' + 10) :              \
-       (parser->buffer.pointer[offset] - (yaml_char_t) '0'))
-#define AS_HEX(parser)  AS_HEX_AT(parser,0)
-/*
- * Check if the character at the specified position is NUL.
- */
-
-#define IS_Z_AT(parser,offset)    CHECK_AT(parser,'\0',(offset))
-
-#define IS_Z(parser)    IS_Z_AT(parser,0)
-
-/*
- * Check if the character at the specified position is BOM.
- */
-
-#define IS_BOM_AT(parser,offset)                                                \
-     (CHECK_AT(parser,'\xEF',(offset))                                          \
-      && CHECK_AT(parser,'\xBB',(offset)+1)                                     \
-      && CHECK_AT(parser,'\xBF',(offset)+1))    /* BOM (#xFEFF) */
-
-#define IS_BOM(parser)  IS_BOM_AT(parser,0)
-
-/*
- * Check if the character at the specified position is space.
- */
-
-#define IS_SPACE_AT(parser,offset)  CHECK_AT(parser,' ',(offset))
-
-#define IS_SPACE(parser)    IS_SPACE_AT(parser,0)
-
-/*
- * Check if the character at the specified position is tab.
- */
-
-#define IS_TAB_AT(parser,offset)    CHECK_AT(parser,'\t',(offset))
-
-#define IS_TAB(parser)  IS_TAB_AT(parser,0)
-
-/*
- * Check if the character at the specified position is blank (space or tab).
- */
-
-#define IS_BLANK_AT(parser,offset)  \
-    (IS_SPACE_AT(parser,(offset)) || IS_TAB_AT(parser,(offset)))
-
-#define IS_BLANK(parser)    IS_BLANK_AT(parser,0)
-
-/*
- * Check if the character at the specified position is a line break.
- */
-
-#define IS_BREAK_AT(parser,offset)                                              \
-    (CHECK_AT(parser,'\r',(offset))                 /* CR (#xD)*/               \
-     || CHECK_AT(parser,'\n',(offset))              /* LF (#xA) */              \
-     || (CHECK_AT(parser,'\xC2',(offset))                                       \
-         && CHECK_AT(parser,'\x85',(offset)+1))     /* NEL (#x85) */            \
-     || (CHECK_AT(parser,'\xE2',(offset))                                       \
-         && CHECK_AT(parser,'\x80',(offset)+1)                                  \
-         && CHECK_AT(parser,'\xA8',(offset)+2))     /* LS (#x2028) */           \
-     || (CHECK_AT(parser,'\xE2',(offset))                                       \
-         && CHECK_AT(parser,'\x80',(offset)+1)                                  \
-         && CHECK_AT(parser,'\xA9',(offset)+2)))    /* PS (#x2029) */
-
-#define IS_BREAK(parser)    IS_BREAK_AT(parser,0)
-
-#define IS_CRLF_AT(parser,offset)                                               \
-     (CHECK_AT(parser,'\r',(offset)) && CHECK_AT(parser,'\n',(offset)+1))
-
-#define IS_CRLF(parser) IS_CRLF_AT(parser,0)
-
-/*
- * Check if the character is a line break or NUL.
- */
-
-#define IS_BREAKZ_AT(parser,offset)                                             \
-    (IS_BREAK_AT(parser,(offset)) || IS_Z_AT(parser,(offset)))
-
-#define IS_BREAKZ(parser)   IS_BREAKZ_AT(parser,0)
-
-/*
- * Check if the character is a line break, space, or NUL.
- */
-
-#define IS_SPACEZ_AT(parser,offset)                                             \
-    (IS_SPACE_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset)))
-
-#define IS_SPACEZ(parser)   IS_SPACEZ_AT(parser,0)
-
-/*
- * Check if the character is a line break, space, tab, or NUL.
- */
-
-#define IS_BLANKZ_AT(parser,offset)                                             \
-    (IS_BLANK_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset)))
-
-#define IS_BLANKZ(parser)   IS_BLANKZ_AT(parser,0)
-
-/*
- * Determine the width of the character.
- */
-
-#define WIDTH_AT(parser,offset)                                                 \
-     ((parser->buffer.pointer[offset] & 0x80) == 0x00 ? 1 :                     \
-      (parser->buffer.pointer[offset] & 0xE0) == 0xC0 ? 2 :                     \
-      (parser->buffer.pointer[offset] & 0xF0) == 0xE0 ? 3 :                     \
-      (parser->buffer.pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
-
-#define WIDTH(parser)   WIDTH_AT(parser,0)
-
 /*
  * Advance the buffer pointer.
  */
      (parser->mark.index ++,                                                    \
       parser->mark.column ++,                                                   \
       parser->unread --,                                                        \
-      parser->buffer.pointer += WIDTH(parser))
+      parser->buffer.pointer += WIDTH(parser->buffer))
 
 #define SKIP_LINE(parser)                                                       \
-     (IS_CRLF(parser) ?                                                         \
+     (IS_CRLF(parser->buffer) ?                                                 \
       (parser->mark.index += 2,                                                 \
        parser->mark.column = 0,                                                 \
        parser->mark.line ++,                                                    \
        parser->unread -= 2,                                                     \
        parser->buffer.pointer += 2) :                                           \
-      IS_BREAK(parser) ?                                                        \
+      IS_BREAK(parser->buffer) ?                                                \
       (parser->mark.index ++,                                                   \
        parser->mark.column = 0,                                                 \
        parser->mark.line ++,                                                    \
        parser->unread --,                                                       \
-       parser->buffer.pointer += WIDTH(parser)) : 0)
+       parser->buffer.pointer += WIDTH(parser->buffer)) : 0)
 
 /*
  * Copy a character to a string buffer and advance pointers.
 
 #define READ(parser,string)                                                     \
      (STRING_EXTEND(parser,string) ?                                            \
-         (((*parser->buffer.pointer & 0x80) == 0x00 ?                           \
-           (*((string).pointer++) = *(parser->buffer.pointer++)) :              \
-           (*parser->buffer.pointer & 0xE0) == 0xC0 ?                           \
-           (*((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++)) :              \
-           (*parser->buffer.pointer & 0xF0) == 0xE0 ?                           \
-           (*((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++)) :              \
-           (*parser->buffer.pointer & 0xF8) == 0xF0 ?                           \
-           (*((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++),                \
-            *((string).pointer++) = *(parser->buffer.pointer++)) : 0),          \
+         (COPY(string,parser->buffer),                                          \
           parser->mark.index ++,                                                \
           parser->mark.column ++,                                               \
           parser->unread --,                                                    \
 
 #define READ_LINE(parser,string)                                                \
     (STRING_EXTEND(parser,string) ?                                             \
-    (((CHECK_AT(parser,'\r',0) && CHECK_AT(parser,'\n',1)) ? /* CR LF -> LF */  \
+    (((CHECK_AT(parser->buffer,'\r',0)                                          \
+       && CHECK_AT(parser->buffer,'\n',1)) ?        /* CR LF -> LF */           \
      (*((string).pointer++) = (yaml_char_t) '\n',                               \
       parser->buffer.pointer += 2,                                              \
       parser->mark.index += 2,                                                  \
       parser->mark.column = 0,                                                  \
       parser->mark.line ++,                                                     \
       parser->unread -= 2) :                                                    \
-     (CHECK_AT(parser,'\r',0) || CHECK_AT(parser,'\n',0)) ? /* CR|LF -> LF */   \
+     (CHECK_AT(parser->buffer,'\r',0)                                           \
+      || CHECK_AT(parser->buffer,'\n',0)) ?         /* CR|LF -> LF */           \
      (*((string).pointer++) = (yaml_char_t) '\n',                               \
       parser->buffer.pointer ++,                                                \
       parser->mark.index ++,                                                    \
       parser->mark.column = 0,                                                  \
       parser->mark.line ++,                                                     \
       parser->unread --) :                                                      \
-     (CHECK_AT(parser,'\xC2',0) && CHECK_AT(parser,'\x85',1)) ? /* NEL -> LF */ \
+     (CHECK_AT(parser->buffer,'\xC2',0)                                         \
+      && CHECK_AT(parser->buffer,'\x85',1)) ?       /* NEL -> LF */             \
      (*((string).pointer++) = (yaml_char_t) '\n',                               \
       parser->buffer.pointer += 2,                                              \
       parser->mark.index ++,                                                    \
       parser->mark.column = 0,                                                  \
       parser->mark.line ++,                                                     \
       parser->unread --) :                                                      \
-     (CHECK_AT(parser,'\xE2',0) &&                                              \
-      CHECK_AT(parser,'\x80',1) &&                                              \
-      (CHECK_AT(parser,'\xA8',2) ||                                             \
-       CHECK_AT(parser,'\xA9',2))) ?                    /* LS|PS -> LS|PS */    \
+     (CHECK_AT(parser->buffer,'\xE2',0) &&                                      \
+      CHECK_AT(parser->buffer,'\x80',1) &&                                      \
+      (CHECK_AT(parser->buffer,'\xA8',2) ||                                     \
+       CHECK_AT(parser->buffer,'\xA9',2))) ?        /* LS|PS -> LS|PS */        \
      (*((string).pointer++) = *(parser->buffer.pointer++),                      \
       *((string).pointer++) = *(parser->buffer.pointer++),                      \
       *((string).pointer++) = *(parser->buffer.pointer++),                      \
@@ -809,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.
@@ -938,11 +744,13 @@ yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token)
     assert(parser); /* Non-NULL parser object is expected. */
     assert(token);  /* Non-NULL token object is expected. */
 
+    /* Erase the token object. */
+
+    memset(token, 0, sizeof(yaml_token_t));
+
     /* No tokens after STREAM-END or error. */
 
     if (parser->stream_end_produced || parser->error) {
-        memset(token, 0, sizeof(yaml_token_t));
-
         return 1;
     }
 
@@ -954,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 ++;
@@ -1086,111 +894,113 @@ yaml_parser_fetch_next_token(yaml_parser_t *parser)
 
     /* Is it the end of the stream? */
 
-    if (IS_Z(parser))
+    if (IS_Z(parser->buffer))
         return yaml_parser_fetch_stream_end(parser);
 
     /* Is it a directive? */
 
-    if (parser->mark.column == 0 && CHECK(parser, '%'))
+    if (parser->mark.column == 0 && CHECK(parser->buffer, '%'))
         return yaml_parser_fetch_directive(parser);
 
     /* Is it the document start indicator? */
 
     if (parser->mark.column == 0
-            && CHECK_AT(parser, '-', 0)
-            && CHECK_AT(parser, '-', 1)
-            && CHECK_AT(parser, '-', 2)
-            && IS_BLANKZ_AT(parser, 3))
+            && CHECK_AT(parser->buffer, '-', 0)
+            && CHECK_AT(parser->buffer, '-', 1)
+            && CHECK_AT(parser->buffer, '-', 2)
+            && IS_BLANKZ_AT(parser->buffer, 3))
         return yaml_parser_fetch_document_indicator(parser,
                 YAML_DOCUMENT_START_TOKEN);
 
     /* Is it the document end indicator? */
 
     if (parser->mark.column == 0
-            && CHECK_AT(parser, '.', 0)
-            && CHECK_AT(parser, '.', 1)
-            && CHECK_AT(parser, '.', 2)
-            && IS_BLANKZ_AT(parser, 3))
+            && CHECK_AT(parser->buffer, '.', 0)
+            && CHECK_AT(parser->buffer, '.', 1)
+            && CHECK_AT(parser->buffer, '.', 2)
+            && IS_BLANKZ_AT(parser->buffer, 3))
         return yaml_parser_fetch_document_indicator(parser,
                 YAML_DOCUMENT_END_TOKEN);
 
     /* Is it the flow sequence start indicator? */
 
-    if (CHECK(parser, '['))
+    if (CHECK(parser->buffer, '['))
         return yaml_parser_fetch_flow_collection_start(parser,
                 YAML_FLOW_SEQUENCE_START_TOKEN);
 
     /* Is it the flow mapping start indicator? */
 
-    if (CHECK(parser, '{'))
+    if (CHECK(parser->buffer, '{'))
         return yaml_parser_fetch_flow_collection_start(parser,
                 YAML_FLOW_MAPPING_START_TOKEN);
 
     /* Is it the flow sequence end indicator? */
 
-    if (CHECK(parser, ']'))
+    if (CHECK(parser->buffer, ']'))
         return yaml_parser_fetch_flow_collection_end(parser,
                 YAML_FLOW_SEQUENCE_END_TOKEN);
 
     /* Is it the flow mapping end indicator? */
 
-    if (CHECK(parser, '}'))
+    if (CHECK(parser->buffer, '}'))
         return yaml_parser_fetch_flow_collection_end(parser,
                 YAML_FLOW_MAPPING_END_TOKEN);
 
     /* Is it the flow entry indicator? */
 
-    if (CHECK(parser, ','))
+    if (CHECK(parser->buffer, ','))
         return yaml_parser_fetch_flow_entry(parser);
 
     /* Is it the block entry indicator? */
 
-    if (CHECK(parser, '-') && IS_BLANKZ_AT(parser, 1))
+    if (CHECK(parser->buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1))
         return yaml_parser_fetch_block_entry(parser);
 
     /* Is it the key indicator? */
 
-    if (CHECK(parser, '?') && (parser->flow_level || IS_BLANKZ_AT(parser, 1)))
+    if (CHECK(parser->buffer, '?')
+            && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1)))
         return yaml_parser_fetch_key(parser);
 
     /* Is it the value indicator? */
 
-    if (CHECK(parser, ':') && (parser->flow_level || IS_BLANKZ_AT(parser, 1)))
+    if (CHECK(parser->buffer, ':')
+            && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1)))
         return yaml_parser_fetch_value(parser);
 
     /* Is it an alias? */
 
-    if (CHECK(parser, '*'))
+    if (CHECK(parser->buffer, '*'))
         return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN);
 
     /* Is it an anchor? */
 
-    if (CHECK(parser, '&'))
+    if (CHECK(parser->buffer, '&'))
         return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN);
 
     /* Is it a tag? */
 
-    if (CHECK(parser, '!'))
+    if (CHECK(parser->buffer, '!'))
         return yaml_parser_fetch_tag(parser);
 
     /* Is it a literal scalar? */
 
-    if (CHECK(parser, '|') && !parser->flow_level)
+    if (CHECK(parser->buffer, '|') && !parser->flow_level)
         return yaml_parser_fetch_block_scalar(parser, 1);
 
     /* Is it a folded scalar? */
 
-    if (CHECK(parser, '>') && !parser->flow_level)
+    if (CHECK(parser->buffer, '>') && !parser->flow_level)
         return yaml_parser_fetch_block_scalar(parser, 0);
 
     /* Is it a single-quoted scalar? */
 
-    if (CHECK(parser, '\''))
+    if (CHECK(parser->buffer, '\''))
         return yaml_parser_fetch_flow_scalar(parser, 1);
 
     /* Is it a double-quoted scalar? */
 
-    if (CHECK(parser, '"'))
+    if (CHECK(parser->buffer, '"'))
         return yaml_parser_fetch_flow_scalar(parser, 0);
 
     /*
@@ -1212,16 +1022,20 @@ yaml_parser_fetch_next_token(yaml_parser_t *parser)
      * The last rule is more restrictive than the specification requires.
      */
 
-    if (!(IS_BLANKZ(parser) || CHECK(parser, '-') || CHECK(parser, '?')
-                || CHECK(parser, ':') || CHECK(parser, ',') || CHECK(parser, '[')
-                || CHECK(parser, ']') || CHECK(parser, '{') || CHECK(parser, '}')
-                || CHECK(parser, '#') || CHECK(parser, '&') || CHECK(parser, '*')
-                || CHECK(parser, '!') || CHECK(parser, '|') || CHECK(parser, '>')
-                || CHECK(parser, '\'') || CHECK(parser, '"') || CHECK(parser, '%')
-                || CHECK(parser, '@') || CHECK(parser, '`')) ||
-            (CHECK(parser, '-') && !IS_BLANK_AT(parser, 1)) ||
+    if (!(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '-')
+                || CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':')
+                || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '[')
+                || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
+                || CHECK(parser->buffer, '}') || CHECK(parser->buffer, '#')
+                || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '*')
+                || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '|')
+                || CHECK(parser->buffer, '>') || CHECK(parser->buffer, '\'')
+                || CHECK(parser->buffer, '"') || CHECK(parser->buffer, '%')
+                || CHECK(parser->buffer, '@') || CHECK(parser->buffer, '`')) ||
+            (CHECK(parser->buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) ||
             (!parser->flow_level &&
-             (CHECK(parser, '?') || CHECK(parser, ':')) && !IS_BLANKZ_AT(parser, 1)))
+             (CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':'))
+             && !IS_BLANKZ_AT(parser->buffer, 1)))
         return yaml_parser_fetch_plain_scalar(parser);
 
     /*
@@ -1264,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;
@@ -1289,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.
@@ -1304,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;
 
@@ -1332,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 ':'");
         }
     }
 
@@ -1359,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;
@@ -1373,7 +1188,7 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
 {
     if (parser->flow_level) {
         parser->flow_level --;
-        POP(parser, parser->simple_keys);
+        (void)POP(parser, parser->simple_keys);
     }
 
     return 1;
@@ -1383,12 +1198,12 @@ 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
-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;
 
@@ -1407,6 +1222,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. */
@@ -1429,13 +1249,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 intendation level, append
+ * becomes less or equal to the column.  For each indentation 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;
 
@@ -1444,7 +1264,7 @@ yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
     if (parser->flow_level)
         return 1;
 
-    /* Loop through the intendation levels in the stack. */
+    /* Loop through the indentation levels in the stack. */
 
     while (parser->indent > column)
     {
@@ -1510,6 +1330,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))
@@ -1809,7 +1636,7 @@ yaml_parser_fetch_key(yaml_parser_t *parser)
 
     if (!parser->flow_level)
     {
-        /* Check if we are allowed to start a new key (not nessesary simple). */
+        /* Check if we are allowed to start a new key (not necessary simple). */
 
         if (!parser->simple_key_allowed) {
             return yaml_parser_set_scanner_error(parser, NULL, parser->mark,
@@ -2099,7 +1926,7 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser)
 
         if (!CACHE(parser, 1)) return 0;
 
-        if (parser->mark.column == 0 && IS_BOM(parser))
+        if (parser->mark.column == 0 && IS_BOM(parser->buffer))
             SKIP(parser);
 
         /*
@@ -2109,22 +1936,22 @@ 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;
 
-        while (CHECK(parser,' ') ||
+        while (CHECK(parser->buffer,' ') ||
                 ((parser->flow_level || !parser->simple_key_allowed) &&
-                 CHECK(parser, '\t'))) {
+                 CHECK(parser->buffer, '\t'))) {
             SKIP(parser);
             if (!CACHE(parser, 1)) return 0;
         }
 
         /* Eat a comment until a line break. */
 
-        if (CHECK(parser, '#')) {
-            while (!IS_BREAKZ(parser)) {
+        if (CHECK(parser->buffer, '#')) {
+            while (!IS_BREAKZ(parser->buffer)) {
                 SKIP(parser);
                 if (!CACHE(parser, 1)) return 0;
             }
@@ -2132,7 +1959,7 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser)
 
         /* If it is a line break, eat it. */
 
-        if (IS_BREAK(parser))
+        if (IS_BREAK(parser->buffer))
         {
             if (!CACHE(parser, 2)) return 0;
             SKIP_LINE(parser);
@@ -2224,7 +2051,7 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token)
     else
     {
         yaml_parser_set_scanner_error(parser, "while scanning a directive",
-                start_mark, "found uknown directive name");
+                start_mark, "found unknown directive name");
         goto error;
     }
 
@@ -2232,13 +2059,13 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token)
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_BLANK(parser)) {
+    while (IS_BLANK(parser->buffer)) {
         SKIP(parser);
         if (!CACHE(parser, 1)) goto error;
     }
 
-    if (CHECK(parser, '#')) {
-        while (!IS_BREAKZ(parser)) {
+    if (CHECK(parser->buffer, '#')) {
+        while (!IS_BREAKZ(parser->buffer)) {
             SKIP(parser);
             if (!CACHE(parser, 1)) goto error;
         }
@@ -2246,15 +2073,15 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token)
 
     /* Check if we are at the end of the line. */
 
-    if (!IS_BREAKZ(parser)) {
+    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;
     }
 
     /* Eat a line break. */
 
-    if (IS_BREAK(parser)) {
+    if (IS_BREAK(parser->buffer)) {
         if (!CACHE(parser, 2)) goto error;
         SKIP_LINE(parser);
     }
@@ -2292,7 +2119,7 @@ yaml_parser_scan_directive_name(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_ALPHA(parser))
+    while (IS_ALPHA(parser->buffer))
     {
         if (!READ(parser, string)) goto error;
         if (!CACHE(parser, 1)) goto error;
@@ -2302,13 +2129,13 @@ 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;
     }
 
     /* Check for an blank character after the name. */
 
-    if (!IS_BLANKZ(parser)) {
+    if (!IS_BLANKZ(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a directive",
                 start_mark, "found unexpected non-alphabetical character");
         goto error;
@@ -2339,7 +2166,7 @@ yaml_parser_scan_version_directive_value(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) return 0;
 
-    while (IS_BLANK(parser)) {
+    while (IS_BLANK(parser->buffer)) {
         SKIP(parser);
         if (!CACHE(parser, 1)) return 0;
     }
@@ -2351,7 +2178,7 @@ yaml_parser_scan_version_directive_value(yaml_parser_t *parser,
 
     /* Eat '.'. */
 
-    if (!CHECK(parser, '.')) {
+    if (!CHECK(parser->buffer, '.')) {
         return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive",
                 start_mark, "did not find expected digit or '.' character");
     }
@@ -2389,7 +2216,7 @@ yaml_parser_scan_version_directive_number(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) return 0;
 
-    while (IS_DIGIT(parser))
+    while (IS_DIGIT(parser->buffer))
     {
         /* Check if the number is too long. */
 
@@ -2398,7 +2225,7 @@ yaml_parser_scan_version_directive_number(yaml_parser_t *parser,
                     start_mark, "found extremely long version number");
         }
 
-        value = value*10 + AS_DIGIT(parser);
+        value = value*10 + AS_DIGIT(parser->buffer);
 
         SKIP(parser);
 
@@ -2436,7 +2263,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_BLANK(parser)) {
+    while (IS_BLANK(parser->buffer)) {
         SKIP(parser);
         if (!CACHE(parser, 1)) goto error;
     }
@@ -2450,7 +2277,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) goto error;
 
-    if (!IS_BLANK(parser)) {
+    if (!IS_BLANK(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive",
                 start_mark, "did not find expected whitespace");
         goto error;
@@ -2458,7 +2285,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
 
     /* Eat whitespaces. */
 
-    while (IS_BLANK(parser)) {
+    while (IS_BLANK(parser->buffer)) {
         SKIP(parser);
         if (!CACHE(parser, 1)) goto error;
     }
@@ -2472,7 +2299,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
 
     if (!CACHE(parser, 1)) goto error;
 
-    if (!IS_BLANKZ(parser)) {
+    if (!IS_BLANKZ(parser->buffer)) {
         yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive",
                 start_mark, "did not find expected whitespace or line break");
         goto error;
@@ -2509,7 +2336,7 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_ALPHA(parser)) {
+    while (IS_ALPHA(parser->buffer)) {
         if (!READ(parser, string)) goto error;
         if (!CACHE(parser, 1)) goto error;
         length ++;
@@ -2524,9 +2351,11 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token,
      *      '?', ':', ',', ']', '}', '%', '@', '`'.
      */
 
-    if (!length || !(IS_BLANKZ(parser) || CHECK(parser, '?') || CHECK(parser, ':') ||
-                CHECK(parser, ',') || CHECK(parser, ']') || CHECK(parser, '}') ||
-                CHECK(parser, '%') || CHECK(parser, '@') || CHECK(parser, '`'))) {
+    if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?')
+                || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',')
+                || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}')
+                || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@')
+                || CHECK(parser->buffer, '`'))) {
         yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ?
                 "while scanning an anchor" : "while scanning an alias", start_mark,
                 "did not find expected alphabetic or numeric character");
@@ -2566,11 +2395,11 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
 
     if (!CACHE(parser, 2)) goto error;
 
-    if (CHECK_AT(parser, '<', 1))
+    if (CHECK_AT(parser->buffer, '<', 1))
     {
         /* Set the handle to '' */
 
-        handle = yaml_malloc(1);
+        handle = YAML_MALLOC(1);
         if (!handle) goto error;
         handle[0] = '\0';
 
@@ -2586,7 +2415,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
 
         /* Check for '>' and eat it. */
 
-        if (!CHECK(parser, '>')) {
+        if (!CHECK(parser->buffer, '>')) {
             yaml_parser_set_scanner_error(parser, "while scanning a tag",
                     start_mark, "did not find the expected '>'");
             goto error;
@@ -2622,7 +2451,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
             /* Set the handle to '!'. */
 
             yaml_free(handle);
-            handle = yaml_malloc(2);
+            handle = YAML_MALLOC(2);
             if (!handle) goto error;
             handle[0] = '!';
             handle[1] = '\0';
@@ -2644,9 +2473,9 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
 
     if (!CACHE(parser, 1)) goto error;
 
-    if (!IS_BLANKZ(parser)) {
+    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;
     }
 
@@ -2680,7 +2509,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
 
     if (!CACHE(parser, 1)) goto error;
 
-    if (!CHECK(parser, '!')) {
+    if (!CHECK(parser->buffer, '!')) {
         yaml_parser_set_scanner_error(parser, directive ?
                 "while scanning a tag directive" : "while scanning a tag",
                 start_mark, "did not find expected '!'");
@@ -2695,7 +2524,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_ALPHA(parser))
+    while (IS_ALPHA(parser->buffer))
     {
         if (!READ(parser, string)) goto error;
         if (!CACHE(parser, 1)) goto error;
@@ -2703,7 +2532,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
 
     /* Check if the trailing character is '!' and copy it. */
 
-    if (CHECK(parser, '!'))
+    if (CHECK(parser->buffer, '!'))
     {
         if (!READ(parser, string)) goto error;
     }
@@ -2746,7 +2575,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;
@@ -2776,17 +2605,24 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
      *      '%'.
      */
 
-    while (IS_ALPHA(parser) || CHECK(parser, ';') || CHECK(parser, '/') ||
-            CHECK(parser, '?') || CHECK(parser, ':') || CHECK(parser, '@') ||
-            CHECK(parser, '&') || CHECK(parser, '=') || CHECK(parser, '+') ||
-            CHECK(parser, '$') || CHECK(parser, ',') || CHECK(parser, '.') ||
-            CHECK(parser, '!') || CHECK(parser, '~') || CHECK(parser, '*') ||
-            CHECK(parser, '\'') || CHECK(parser, '(') || CHECK(parser, ')') ||
-            CHECK(parser, '[') || CHECK(parser, ']') || CHECK(parser, '%'))
+    while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';')
+            || CHECK(parser->buffer, '/') || CHECK(parser->buffer, '?')
+            || CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@')
+            || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=')
+            || CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$')
+            || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '.')
+            || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~')
+            || CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'')
+            || CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')')
+            || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
+            || CHECK(parser->buffer, '%'))
     {
         /* Check if it is a URI-escape sequence. */
 
-        if (CHECK(parser, '%')) {
+        if (CHECK(parser->buffer, '%')) {
+            if (!STRING_EXTEND(parser, string))
+                goto error;
+
             if (!yaml_parser_scan_uri_escapes(parser,
                         directive, start_mark, &string)) goto error;
         }
@@ -2839,7 +2675,9 @@ yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive,
 
         if (!CACHE(parser, 3)) return 0;
 
-        if (!(CHECK(parser, '%') && IS_HEX_AT(parser, 1) && IS_HEX_AT(parser, 2))) {
+        if (!(CHECK(parser->buffer, '%')
+                    && IS_HEX_AT(parser->buffer, 1)
+                    && IS_HEX_AT(parser->buffer, 2))) {
             return yaml_parser_set_scanner_error(parser, directive ?
                     "while parsing a %TAG directive" : "while parsing a tag",
                     start_mark, "did not find URI escaped octet");
@@ -2847,7 +2685,7 @@ yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive,
 
         /* Get the octet. */
 
-        octet = (AS_HEX_AT(parser, 1) << 4) + AS_HEX_AT(parser, 2);
+        octet = (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2);
 
         /* If it is the leading octet, determine the length of the UTF-8 sequence. */
 
@@ -2921,11 +2759,11 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     /* Check for a chomping indicator. */
 
-    if (CHECK(parser, '+') || CHECK(parser, '-'))
+    if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-'))
     {
         /* Set the chomping method and eat the indicator. */
 
-        chomping = CHECK(parser, '+') ? +1 : -1;
+        chomping = CHECK(parser->buffer, '+') ? +1 : -1;
 
         SKIP(parser);
 
@@ -2933,19 +2771,19 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         if (!CACHE(parser, 1)) goto error;
 
-        if (IS_DIGIT(parser))
+        if (IS_DIGIT(parser->buffer))
         {
-            /* Check that the intendation is greater than 0. */
+            /* Check that the indentation is greater than 0. */
 
-            if (CHECK(parser, '0')) {
+            if (CHECK(parser->buffer, '0')) {
                 yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
-                        start_mark, "found an intendation indicator equal to 0");
+                        start_mark, "found an indentation indicator equal to 0");
                 goto error;
             }
 
-            /* Get the intendation level and eat the indicator. */
+            /* Get the indentation level and eat the indicator. */
 
-            increment = AS_DIGIT(parser);
+            increment = AS_DIGIT(parser->buffer);
 
             SKIP(parser);
         }
@@ -2953,22 +2791,22 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     /* Do the same as above, but in the opposite order. */
 
-    else if (IS_DIGIT(parser))
+    else if (IS_DIGIT(parser->buffer))
     {
-        if (CHECK(parser, '0')) {
+        if (CHECK(parser->buffer, '0')) {
             yaml_parser_set_scanner_error(parser, "while scanning a block scalar",
-                    start_mark, "found an intendation indicator equal to 0");
+                    start_mark, "found an indentation indicator equal to 0");
             goto error;
         }
 
-        increment = AS_DIGIT(parser);
+        increment = AS_DIGIT(parser->buffer);
 
         SKIP(parser);
 
         if (!CACHE(parser, 1)) goto error;
 
-        if (CHECK(parser, '+') || CHECK(parser, '-')) {
-            chomping = CHECK(parser, '+') ? +1 : -1;
+        if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) {
+            chomping = CHECK(parser->buffer, '+') ? +1 : -1;
 
             SKIP(parser);
         }
@@ -2978,13 +2816,13 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_BLANK(parser)) {
+    while (IS_BLANK(parser->buffer)) {
         SKIP(parser);
         if (!CACHE(parser, 1)) goto error;
     }
 
-    if (CHECK(parser, '#')) {
-        while (!IS_BREAKZ(parser)) {
+    if (CHECK(parser->buffer, '#')) {
+        while (!IS_BREAKZ(parser->buffer)) {
             SKIP(parser);
             if (!CACHE(parser, 1)) goto error;
         }
@@ -2992,22 +2830,22 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
     /* Check if we are at the end of the line. */
 
-    if (!IS_BREAKZ(parser)) {
+    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;
     }
 
     /* Eat a line break. */
 
-    if (IS_BREAK(parser)) {
+    if (IS_BREAK(parser->buffer)) {
         if (!CACHE(parser, 2)) goto error;
         SKIP_LINE(parser);
     }
 
     end_mark = parser->mark;
 
-    /* Set the intendation level if it was specified. */
+    /* Set the indentation level if it was specified. */
 
     if (increment) {
         indent = parser->indent >= 0 ? parser->indent+increment : increment;
@@ -3022,7 +2860,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))
+    while ((int)parser->mark.column == indent && !IS_Z(parser->buffer))
     {
         /*
          * We are at the beginning of a non-empty line.
@@ -3030,7 +2868,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         /* Is it a trailing whitespace? */
 
-        trailing_blank = IS_BLANK(parser);
+        trailing_blank = IS_BLANK(parser->buffer);
 
         /* Check if we need to fold the leading line break. */
 
@@ -3058,11 +2896,11 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         /* Is it a leading whitespace? */
 
-        leading_blank = IS_BLANK(parser);
+        leading_blank = IS_BLANK(parser->buffer);
 
         /* Consume the current line. */
 
-        while (!IS_BREAKZ(parser)) {
+        while (!IS_BREAKZ(parser->buffer)) {
             if (!READ(parser, string)) goto error;
             if (!CACHE(parser, 1)) goto error;
         }
@@ -3073,7 +2911,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 intendation spaces and line breaks. */
+        /* Eat the following indentation spaces and line breaks. */
 
         if (!yaml_parser_scan_block_scalar_breaks(parser,
                     &indent, &trailing_breaks, start_mark, &end_mark)) goto error;
@@ -3108,8 +2946,8 @@ error:
 }
 
 /*
- * Scan intendation spaces and line breaks for a block scalar.  Determine the
- * intendation level if needed.
+ * Scan indentation spaces and line breaks for a block scalar.  Determine the
+ * indentation level if needed.
  */
 
 static int
@@ -3121,32 +2959,34 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
 
     *end_mark = parser->mark;
 
-    /* Eat the intendation spaces and line breaks. */
+    /* Eat the indentation spaces and line breaks. */
 
     while (1)
     {
-        /* Eat the intendation spaces. */
+        /* Eat the indentation spaces. */
 
         if (!CACHE(parser, 1)) return 0;
 
-        while ((!*indent || parser->mark.column < *indent) && IS_SPACE(parser)) {
+        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. */
+        /* Check for a tab character messing the indentation. */
 
-        if ((!*indent || parser->mark.column < *indent) && IS_TAB(parser)) {
+        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");
+                    start_mark, "found a tab character where an indentation space is expected");
         }
 
         /* Have we found a non-empty line? */
 
-        if (!IS_BREAK(parser)) break;
+        if (!IS_BREAK(parser->buffer)) break;
 
         /* Consume the line break. */
 
@@ -3165,7 +3005,7 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser,
             *indent = 1;
     }
 
-   return 1; 
+   return 1;
 }
 
 /*
@@ -3204,13 +3044,13 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
         if (!CACHE(parser, 4)) goto error;
 
         if (parser->mark.column == 0 &&
-            ((CHECK_AT(parser, '-', 0) &&
-              CHECK_AT(parser, '-', 1) &&
-              CHECK_AT(parser, '-', 2)) ||
-             (CHECK_AT(parser, '.', 0) &&
-              CHECK_AT(parser, '.', 1) &&
-              CHECK_AT(parser, '.', 2))) &&
-            IS_BLANKZ_AT(parser, 3))
+            ((CHECK_AT(parser->buffer, '-', 0) &&
+              CHECK_AT(parser->buffer, '-', 1) &&
+              CHECK_AT(parser->buffer, '-', 2)) ||
+             (CHECK_AT(parser->buffer, '.', 0) &&
+              CHECK_AT(parser->buffer, '.', 1) &&
+              CHECK_AT(parser->buffer, '.', 2))) &&
+            IS_BLANKZ_AT(parser->buffer, 3))
         {
             yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar",
                     start_mark, "found unexpected document indicator");
@@ -3219,7 +3059,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         /* Check for EOF. */
 
-        if (IS_Z(parser)) {
+        if (IS_Z(parser->buffer)) {
             yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar",
                     start_mark, "found unexpected end of stream");
             goto error;
@@ -3231,11 +3071,12 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         leading_blanks = 0;
 
-        while (!IS_BLANKZ(parser))
+        while (!IS_BLANKZ(parser->buffer))
         {
             /* Check for an escaped single quote. */
 
-            if (single && CHECK_AT(parser, '\'', 0) && CHECK_AT(parser, '\'', 1))
+            if (single && CHECK_AT(parser->buffer, '\'', 0)
+                    && CHECK_AT(parser->buffer, '\'', 1))
             {
                 if (!STRING_EXTEND(parser, string)) goto error;
                 *(string.pointer++) = '\'';
@@ -3245,14 +3086,15 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
             /* Check for the right quote. */
 
-            else if (CHECK(parser, single ? '\'' : '"'))
+            else if (CHECK(parser->buffer, single ? '\'' : '"'))
             {
                 break;
             }
 
             /* Check for an escaped line break. */
 
-            else if (!single && CHECK(parser, '\\') && IS_BREAK_AT(parser, 1))
+            else if (!single && CHECK(parser->buffer, '\\')
+                    && IS_BREAK_AT(parser->buffer, 1))
             {
                 if (!CACHE(parser, 3)) goto error;
                 SKIP(parser);
@@ -3263,9 +3105,9 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
             /* Check for an escape sequence. */
 
-            else if (!single && CHECK(parser, '\\'))
+            else if (!single && CHECK(parser->buffer, '\\'))
             {
-                int code_length = 0;
+                size_t code_length = 0;
 
                 if (!STRING_EXTEND(parser, string)) goto error;
 
@@ -3318,8 +3160,8 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
                         *(string.pointer++) = '"';
                         break;
 
-                    case '\'':
-                        *(string.pointer++) = '\'';
+                    case '/':
+                        *(string.pointer++) = '/';
                         break;
 
                     case '\\':
@@ -3374,19 +3216,19 @@ 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. */
 
                     if (!CACHE(parser, code_length)) goto error;
 
                     for (k = 0; k < code_length; k ++) {
-                        if (!IS_HEX_AT(parser, k)) {
+                        if (!IS_HEX_AT(parser->buffer, k)) {
                             yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar",
                                     start_mark, "did not find expected hexdecimal number");
                             goto error;
                         }
-                        value = (value << 4) + AS_HEX_AT(parser, k);
+                        value = (value << 4) + AS_HEX_AT(parser->buffer, k);
                     }
 
                     /* Check the value and write the character. */
@@ -3436,16 +3278,21 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
 
         /* Check if we are at the end of the scalar. */
 
-        if (CHECK(parser, single ? '\'' : '"'))
+        /* Fix for crash unitialized value crash
+         * Credit for the bug and input is to OSS Fuzz
+         * Credit for the fix to Alex Gaynor
+         */
+        if (!CACHE(parser, 1)) goto error;
+        if (CHECK(parser->buffer, single ? '\'' : '"'))
             break;
 
         /* Consume blank characters. */
 
         if (!CACHE(parser, 1)) goto error;
 
-        while (IS_BLANK(parser) || IS_BREAK(parser))
+        while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer))
         {
-            if (IS_BLANK(parser))
+            if (IS_BLANK(parser->buffer))
             {
                 /* Consume a space or a tab character. */
 
@@ -3566,26 +3413,28 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
         if (!CACHE(parser, 4)) goto error;
 
         if (parser->mark.column == 0 &&
-            ((CHECK_AT(parser, '-', 0) &&
-              CHECK_AT(parser, '-', 1) &&
-              CHECK_AT(parser, '-', 2)) ||
-             (CHECK_AT(parser, '.', 0) &&
-              CHECK_AT(parser, '.', 1) &&
-              CHECK_AT(parser, '.', 2))) &&
-            IS_BLANKZ_AT(parser, 3)) break;
+            ((CHECK_AT(parser->buffer, '-', 0) &&
+              CHECK_AT(parser->buffer, '-', 1) &&
+              CHECK_AT(parser->buffer, '-', 2)) ||
+             (CHECK_AT(parser->buffer, '.', 0) &&
+              CHECK_AT(parser->buffer, '.', 1) &&
+              CHECK_AT(parser->buffer, '.', 2))) &&
+            IS_BLANKZ_AT(parser->buffer, 3)) break;
 
         /* Check for a comment. */
 
-        if (CHECK(parser, '#'))
+        if (CHECK(parser->buffer, '#'))
             break;
 
         /* Consume non-blank characters. */
 
-        while (!IS_BLANKZ(parser))
+        while (!IS_BLANKZ(parser->buffer))
         {
             /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */
 
-            if (parser->flow_level && CHECK(parser, ':') && !IS_BLANKZ_AT(parser, 1)) {
+            if (parser->flow_level
+                    && CHECK(parser->buffer, ':')
+                    && !IS_BLANKZ_AT(parser->buffer, 1)) {
                 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
                         start_mark, "found unexpected ':'");
                 goto error;
@@ -3593,12 +3442,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
 
             /* Check for indicators that may end a plain scalar. */
 
-            if ((CHECK(parser, ':') && IS_BLANKZ_AT(parser, 1)) ||
-                    (parser->flow_level &&
-                     (CHECK(parser, ',') || CHECK(parser, ':') ||
-                      CHECK(parser, '?') || CHECK(parser, '[') ||
-                      CHECK(parser, ']') || CHECK(parser, '{') ||
-                      CHECK(parser, '}'))))
+            if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))
+                    || (parser->flow_level &&
+                        (CHECK(parser->buffer, ',') || CHECK(parser->buffer, ':')
+                         || CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[')
+                         || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
+                         || CHECK(parser->buffer, '}'))))
                 break;
 
             /* Check if we need to join whitespaces and breaks. */
@@ -3647,22 +3496,23 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
 
         /* Is it the end? */
 
-        if (!(IS_BLANK(parser) || IS_BREAK(parser)))
+        if (!(IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)))
             break;
 
         /* Consume blank characters. */
 
         if (!CACHE(parser, 1)) goto error;
 
-        while (IS_BLANK(parser) || IS_BREAK(parser))
+        while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer))
         {
-            if (IS_BLANK(parser))
+            if (IS_BLANK(parser->buffer))
             {
-                /* Check for tab character that abuse intendation. */
+                /* Check for tab character that abuse indentation. */
 
-                if (leading_blanks && parser->mark.column < indent && IS_TAB(parser)) {
+                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");
+                            start_mark, "found a tab character that violate indentation");
                     goto error;
                 }
 
@@ -3695,9 +3545,9 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
             if (!CACHE(parser, 1)) goto error;
         }
 
-        /* Check intendation level. */
+        /* Check indentation level. */
 
-        if (!parser->flow_level && parser->mark.column < indent)
+        if (!parser->flow_level && (int)parser->mark.column < indent)
             break;
     }
 
@@ -3726,4 +3576,3 @@ error:
 
     return 0;
 }
-
This page took 1.163673 seconds and 4 git commands to generate.