* htmlParseComment: * @ctxt: an HTML parser context * * Parse an HTML comment */
| 3351 | * Parse an HTML comment |
| 3352 | */ |
| 3353 | static void |
| 3354 | htmlParseComment(htmlParserCtxtPtr ctxt) { |
| 3355 | xmlChar *buf = NULL; |
| 3356 | int len; |
| 3357 | int size = HTML_PARSER_BUFFER_SIZE; |
| 3358 | int q, ql; |
| 3359 | int r, rl; |
| 3360 | int cur, l; |
| 3361 | int next, nl; |
| 3362 | int maxLength = (ctxt->options & XML_PARSE_HUGE) ? |
| 3363 | XML_MAX_HUGE_LENGTH : |
| 3364 | XML_MAX_TEXT_LENGTH; |
| 3365 | xmlParserInputState state; |
| 3366 | |
| 3367 | /* |
| 3368 | * Check that there is a comment right here. |
| 3369 | */ |
| 3370 | if ((RAW != '<') || (NXT(1) != '!') || |
| 3371 | (NXT(2) != '-') || (NXT(3) != '-')) return; |
| 3372 | |
| 3373 | state = ctxt->instate; |
| 3374 | ctxt->instate = XML_PARSER_COMMENT; |
| 3375 | SKIP(4); |
| 3376 | buf = (xmlChar *) xmlMallocAtomic(size); |
| 3377 | if (buf == NULL) { |
| 3378 | htmlErrMemory(ctxt); |
| 3379 | return; |
| 3380 | } |
| 3381 | len = 0; |
| 3382 | buf[len] = 0; |
| 3383 | q = CUR_CHAR(ql); |
| 3384 | if (q == 0) |
| 3385 | goto unfinished; |
| 3386 | if (q == '>') { |
| 3387 | htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL); |
| 3388 | cur = '>'; |
| 3389 | goto finished; |
| 3390 | } |
| 3391 | NEXTL(ql); |
| 3392 | r = CUR_CHAR(rl); |
| 3393 | if (r == 0) |
| 3394 | goto unfinished; |
| 3395 | if (q == '-' && r == '>') { |
| 3396 | htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL); |
| 3397 | cur = '>'; |
| 3398 | goto finished; |
| 3399 | } |
| 3400 | NEXTL(rl); |
| 3401 | cur = CUR_CHAR(l); |
| 3402 | while ((cur != 0) && |
| 3403 | ((cur != '>') || |
| 3404 | (r != '-') || (q != '-'))) { |
| 3405 | NEXTL(l); |
| 3406 | next = CUR_CHAR(nl); |
| 3407 | |
| 3408 | if ((q == '-') && (r == '-') && (cur == '!') && (next == '>')) { |
| 3409 | htmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, |
| 3410 | "Comment incorrectly closed by '--!>'", NULL, NULL); |
no test coverage detected